[英]FluentNHibernate Lookup Table
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. 我受困的部分是此查询的FluentNHibernate映射。 Within my ProductMap class, I have the following mapping:
在我的ProductMap类中,我具有以下映射:
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). 当前正在创建一个查询,该查询在Product表而不是查找表(AccessoryProduct)中查找“ ParentProductID”。
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. 感谢您提供任何帮助,即使它涉及xml映射。 I should be able to figure out the fluent side.
我应该能够弄清楚流利的一面。
You need a Many-to-Many relationship. 您需要多对多关系。
Try: 尝试:
HasManyToMany(x => x.Accessories)
.Table("AccessoryProduct")
.ParentKeyColumn("ParentProductID")
.ChildKeyColumn("ChildProductID")
.Cascade.None()
.Inverse()
.LazyLoad();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.