The*_*Mar 3 nhibernate nhibernate-mapping fluent-nhibernate value-objects
我将我的值Object Item作为组件映射到下面的映射配置
{
Table("Product");
Not.LazyLoad();
Id(x => x.Id, "id");
Map(x => x.Number, "number");
Map(x => x.Name, "name");
Map(x => x.Description, "description");
Map(x => x.Status, "status");
HasMany(x => x.ItemLines).Component(
m =>
{
m.Map(x => x.ItemId, "itemid");
m.Map(x => x.Qty, "quantity");
}).Table("productitems").KeyColumn("itemid");
}
Class structure
public class ItemLine
{
public Product Product { get; set; }
public Guid ItemId { get; set; }
public int Qty { get; set; }
public ItemLine()
{
}
public ItemLine(Product product, Guid itemId, int qty)
{
Product = product;
ItemId = itemId;
Qty = qty;
}
//Equality and GetHashCode implemented.....
}
Run Code Online (Sandbox Code Playgroud)
我能够将数据插入到数据库中,但在按产品ID检索时,项目行中的Product属性为null.
我是否需要传递Mapping中的任何引用>
请帮忙
谢谢,
损伤
好.通过反复试验解决.
添加m.ParentReference(x => x.Product);
{
Table("Product");
Not.LazyLoad();
Id(x => x.Id, "id");
Map(x => x.Number, "number");
Map(x => x.Name, "name");
Map(x => x.Description, "description");
Map(x => x.Status, "status");
HasMany(x => x.ItemLines).Component(
m =>
{
m.Map(x => x.ItemId, "itemid");
m.Map(x => x.Qty, "quantity");
m.ParentReference(x => x.Product);
}).Table("productitems").KeyColumn("itemid");
}
Run Code Online (Sandbox Code Playgroud)
希望这有助于某人.
| 归档时间: |
|
| 查看次数: |
979 次 |
| 最近记录: |