1

I have the following situation in a legacy database [sample]

table1   
**ID_TABLE1 [PK]   
ID_SOURCE** [PK]   


table2   
**ID_TABLE2 [PK]   
ID_SOURCE** [PK]   


table3   
**ID_TABLE3 [PK]   
ID_SOURCE** [PK][FK]   
ID_TABLE2 [FK]   
ID_TABLE1 [FK]   



 public partial classTable3Map : ClassMap<TABLE3>
    {
        public classTable3Map()
        {
            Table("TABLE3");
            LazyLoad();
            CompositeId().KeyProperty(x => x.ID_TABLE3 , "ID_TABLE3").KeyProperty(x => x.ID_SOURCE, "ID_SOURCE");
          References(x => x.TABLE1).Columns("ID_TABLE1 ", "ID_SOURCE");
          References(x => x.TABLE2).Columns("ID_TABLE2 ", "ID_SOURCE");
        }
    }

When i try to save this type of objects nhibernate throw a

**System.IndexOutOfRangeException**    
  Message=Index xx non valid  for xxxParameterCollection

I'll see that it have more input then parameter (the duplicates ID_SOURCE columns)

When i try to map a n to m relation is the same situation.

I can save if i map the id instead of objects (reference) and save childrens before insert but i have to rewrite the model and doing many manual adjustement.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Andreanta
  • 175
  • 1
  • 8

1 Answers1

0

unfortunatly it is not possible to specify a column as both part of the primary key and foreignkey see here for similar question.

Options i see:

  • make the references .Readonly()
  • try to implement ICompositeUserType for the references but you'll lose eager loading and querying
Community
  • 1
  • 1
Firo
  • 30,626
  • 4
  • 55
  • 94