mapping with specific foreign key

Matteo's Avatar

Matteo

19 May, 2010 02:18 PM via web

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?

  1. 2 Posted by Ross Beehler on 19 May, 2010 04:13 PM

    Ross Beehler's Avatar

    They column in "KeyColumn()" should be the column on the 'child' table, so you should change your HasMany to say ".KeyColumn("main_a_id")".

  2. 3 Posted by Matteo on 20 May, 2010 08:03 AM

    Matteo's Avatar

    It returns this error:

    illegal access to loading collection

  3. 4 Posted by Ross Beehler on 20 May, 2010 04:20 PM

    Ross Beehler's Avatar

    May want to post the full stack of the error along with the code, as that may be caused by something else.

  4. Support Staff 5 Posted by Paul Batum on 21 May, 2010 11:09 PM

    Paul Batum's Avatar

    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.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What day comes after Monday?