I
I
Ilya2016-09-06 17:54:05
NHibernate
Ilya, 2016-09-06 17:54:05

How to map a one-to-many relationship in Fluent NHibernate when the foreign key is on the "one" side?

Faced the problem of describing a one-to-many relationship with a non-standard table structure. There are 2 tables FOO and BAR which are related as FOO(1)->BAR(*). At the same time, FOO has an ID_BAR column, which points to a set of records from BAR, and BAR has a non-unique CODE column, the value of which is contained in ID_BAR. You need to bind these tables to the appropriate classes:

class Foo
{
    public virtual IList<Bar> Bars { get; set; }
}
class Bar
{
    public virtual string Code { get; set; }
    public virtual Foo Foo { get; set; }
}

If the foreign key were in BAR, there would be much less problems, and all mapping would be reduced to HasMany, but in this situation, I have no idea how mapping can be done.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question