Fluent NHibernate 外键为 Null,来自查找表
我有一个包含产品(产品表)的查找表、一个包含订单详细信息的 CustomerOrder 表和一个包含每个订购产品的行的 OrderLines 表。
因此,实体看起来像这样
OrderLine
Id
..stuff..
Product
Product
Id
ProductInfo
表看起来相同,除了 ProductId 外键而不是 Product。 映射覆盖看起来像这样
对于 OrderLine
mapping.HasOne(x => x.Product)
.Fetch.Join()
.Cascade.All();
确实如此。问题是这样的,在上面的语句中,一个 null 被插入作为 ProductId 外键,如果我删除映射,它可以正常工作,但这会导致系统中进一步进行多个(如数千个)选择。我在这里缺少什么?如果我将虚拟放回到 Product 中的 OrderLine,那么 NHibernate 会尝试更新这两个实体(即,它尝试在已经存在的产品表中插入一条新记录。我如何告诉 NHibernate 有关此关系的信息,而不尝试更新)产品?
帮助将不胜感激。
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 tables 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
mapping.References(x => x.Product)
而不是mapping.HasOne(x => x.Product)
。Use
mapping.References(x => x.Product)
instead ofmapping.HasOne(x => x.Product)
.