Nhibernate 组件映射:从数据库查询时值对象中的父对象为 null
我使用以下映射配置将值对象项映射为组件,
{
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.....
}
我能够将数据插入数据库,但在按产品 ID 检索时,项行中的产品属性为空。
我需要在映射中传递任何参考吗?
请帮忙
谢谢你,
马尔
I am mapping my value Object Item as component withthe folowing mapping configuration
{
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.....
}
I am able to insert data to Database but while retrieving back by Product Id, the Product property in Item Line is null.
Do I need to pass any References in Mapping>
Please help
Thank you,
Mar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。通过反复试验解决。
添加 m.ParentReference(x => x.Product);
希望这对某人有帮助。
Ok. Solved by trial and error.
Add m.ParentReference(x => x.Product);
hope this helps someone.