开发者

Fluent NHibernate Foreign Key is Null, from lookup table

I have a lookup table that contains products (Product table) a CustomerOrder table that contains order details and an OrderLines table that contains a line per product ordered.

So the entities look something like this

OrderLine

Id
..stuff..
Product

Product

Id
ProductInfo

The tab开发者_运维问答les look the same except instead of Product there is a ProductId foreign key. The mapping overrides look like this

For OrderLine

mapping.HasOne(x => x.Product)
        .Fetch.Join()
        .Cascade.All();

That is it really. The problem is this, with the above statement a null gets inserted as the ProductId foreign key, if I remove the mapping it works correctly, but this causes multiple (as in thousands) of selects further on in the system. What am I missing here ? If I put a virtual back to OrderLine in Product, then NHibernate tries to update both entities (i.e. it tries to insert a new record in the product table, which already exists. How do I tell NHibernate about this relationship, without it trying to update Products ?

Help would be most appreciated.


Use mapping.References(x => x.Product) instead of mapping.HasOne(x => x.Product).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜