John Doe
John Doe

Reputation: 49

Many to one mapping

I have a tabel that looks like,

tabel1

someID PK, node

tabel2

nodeID PK, node

and I am trying to make to make the following in nhibernate instead of sql

SELECT *
FROM tabel1 
LEFT OUTER JOIN tabel2 
ON tabel1.node = tabel2.nodeid

I have tried (and it is a many to one relation because Tabel2 can have several Tabel1 relations)

Tabel1 mapping file

        References(x => x.Tabel2)
            .Column("nodeID")
            .Not.LazyLoad();

Tabel2 mapping file

        HasMany(x => x.Tabel1)
            .KeyColumn("node")
            .Not.LazyLoad();

I dont get why this is not working!

Upvotes: 0

Views: 82

Answers (1)

Firo
Firo

Reputation: 30813

.Column("nodeID") has to be .Column("node") because it is the column in table 1 pointing to the id (default) of table2

Upvotes: 1

Related Questions