FluentNHibernate 一对多映射
我是 NHibernate 和 NHibernate 的新手。 FNH。以下是我想要实现的基本场景 有两个实体映射器类“Customer”和“Customer”。 “订单”
客户
Table("CUSTOMERTEST");
LazyLoad();
Id(x => x.CustomerId).Column("CustomerId").GeneratedBy.Sequence("SYS");
Map(x => x.CompanyName).Column("CompanyName");
Map(x => x.ContactName).Column("ContactName");
HasMany(x => x.Orders).KeyColumn("CustomerId").Cascade.All().Table("ORDERTEST").AsBag();
订单
Table("ORDERTEST");
LazyLoad();
Id(x => x.OrderId).Column("OrderId").GeneratedBy.Sequence("SYS");
References(x => x.OrderedBy).Column("CustomerId");
References(x => x.ProductDetails).Column("ProductId");
Map(x => x.OrderDate).Column("OrderDate");
Map(x => x.ShipToName).Column("ShipToName");
我试图通过客户实体类中的以下属性获取特定客户的订单详细信息。
public virtual IList<Order> Orders {
get { return new List<Order>(orders).AsReadOnly(); }
protected set { orders = value; }
}
但我能够获取客户实体对象中的客户详细信息,但特定客户的“订单”始终为空。我没有进行任何更新操作,我只需要从数据库中获取数据。艾米,我做错了什么,或者我们怎样才能得到这个?
提前致谢
I am novice to NHibernate & FNH. Below is the basic scenario I am trying to achieve
There are two entity mapper classes "Customer" & "Order"
Customer
Table("CUSTOMERTEST");
LazyLoad();
Id(x => x.CustomerId).Column("CustomerId").GeneratedBy.Sequence("SYS");
Map(x => x.CompanyName).Column("CompanyName");
Map(x => x.ContactName).Column("ContactName");
HasMany(x => x.Orders).KeyColumn("CustomerId").Cascade.All().Table("ORDERTEST").AsBag();
Order
Table("ORDERTEST");
LazyLoad();
Id(x => x.OrderId).Column("OrderId").GeneratedBy.Sequence("SYS");
References(x => x.OrderedBy).Column("CustomerId");
References(x => x.ProductDetails).Column("ProductId");
Map(x => x.OrderDate).Column("OrderDate");
Map(x => x.ShipToName).Column("ShipToName");
I am trying to fetch the order details for a particular customer though property as below in the customer entity class.
public virtual IList<Order> Orders {
get { return new List<Order>(orders).AsReadOnly(); }
protected set { orders = value; }
}
But I am able to fetch the customer details in the customer entity object but he "Orders" for the particular customer is always empty. I am not doing any update operations, I just need to fetch the data from DB only. Amy I doing something wrong or how can we get this?
Thanks In Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 Customer 类中:
您还可以添加公共方法来添加或删除订单中的项目
In your Customer class:
also you can add public methods to add or remove items from Orders