FluentNHibernate 查找表
这可能是一个我似乎无法克服的简单问题。
我创建了一个“产品”类,其中包含“配件”列表。每个“配件”只是查找表引用的另一个产品。
表设置:
Product
-------
ProductID int
Name varchar(200)
AccessoryProduct
----------------
ID int
ParentProductID int
ChildProductID int
我希望能够以如下方式访问此附件列表:
foreach(Product p in product.Accessories)
string s = p.Name;
我困惑的部分是用于此查找的 FluentNHibernate 映射。在我的 ProductMap 类中,我有以下映射:
Id(x => x.ProductID);
Map(x => x.Name);
HasMany(x => x.Accessories)
.Table("AccessoryProduct")
.KeyColumn("ParentProductID")
.Cascade.None()
.Inverse()
.LazyLoad();
当前正在创建一个查询,用于在 Product 表而不是查找表(AccessoryProduct)中查找“ParentProductID”。
我是否缺少一种简单的方法来实现查找表的流畅映射?
任何帮助都会受到赞赏,即使它涉及 xml 映射。我应该能够弄清楚流畅的一面。
This is possibly an easy one that I can't seem to get past.
I've created a "Product" class which has a list of "Accessories". Each "Accessory" is just another product referenced by a lookup table.
Table setup:
Product
-------
ProductID int
Name varchar(200)
AccessoryProduct
----------------
ID int
ParentProductID int
ChildProductID int
I'd like to be able to access this list of accessories in a manner such as:
foreach(Product p in product.Accessories)
string s = p.Name;
The part I'm stumped on is the FluentNHibernate mapping for this lookup. Within my ProductMap class, I have the following mapping:
Id(x => x.ProductID);
Map(x => x.Name);
HasMany(x => x.Accessories)
.Table("AccessoryProduct")
.KeyColumn("ParentProductID")
.Cascade.None()
.Inverse()
.LazyLoad();
This is currently creating a query that looks for "ParentProductID" within the Product table instead of the lookup table(AccessoryProduct).
Is there a simple method I'm missing that allows for a fluent mapping of a lookup table?
Any assistance is appreciated, even if it involves the xml mapping. I should be able to figure out the fluent side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要多对多关系。
尝试:
You need a Many-to-Many relationship.
Try: