mapping with specific foreign key
Good morning,
i got 2 tables
A
id
name
B
id
main_a_id
name
And i need to map collections of B in A such as:
HasMany(x => x.B)
.KeyColumn("id")
.AsSet();
i need to specify that my foreign key is main_a_id.
How could i do?
2 Posted by Ross Beehler on 19 May, 2010 04:13 PM
They column in "KeyColumn()" should be the column on the 'child' table, so you should change your HasMany to say ".KeyColumn("main_a_id")".
3 Posted by Matteo on 20 May, 2010 08:03 AM
It returns this error:
illegal access to loading collection
4 Posted by Ross Beehler on 20 May, 2010 04:20 PM
May want to post the full stack of the error along with the code, as that may be caused by something else.
Support Staff 5 Posted by Paul Batum on 21 May, 2010 11:09 PM
The "illegal access to loading collection" error usually occurs when you
have gotten something wrong on your domain objects and the mapping of
whether nhibernate should use properties or should use the backing fields.
Remember that the default behavior for nhibernate is to use your properties
to set the values on the objects its loading, and if you have any code in
the setter of those properties, it will run. You can use the .Access
property on many mapping types to control this.