0

I have simple task. I need map reference to properity and their ID to other properity.

If I use this map I get error:

"Additional information: Invalid index 24 for this SqlParameterCollection with Count=24."

    public CityMap()
    {
        Map(x => x.Name).Not.Nullable();
        //Map(x => x.AddressID); //This line makes trouble

        References(x => x.Address);
lru83989
  • 1
  • 2

1 Answers1

2

We can do it for read operation (I am quite happy to use this approach). Just, one of these properties must be insert="false" and update="false".

In fluent it should be like this:

...
Map(x => x.AddressID)
   .Insert(false).Udpate(false)
   // or just 
   // .ReadOnly()
   ;
References(x => x.Address);

We just have to decide which will be the readonly. Reference? or ValueType? I would make Reference editable, because then all NHibernate built in features will work (e.g. assign to transient object will properly later insert the just created ID)

Also check these for some more details check this or here.

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Is Mapping between Objects in nHibernate only possible in fluent-hibernate? Or could I also make this work in 'normal' nHibernate? – Snickbrack Mar 16 '19 at 12:39