如何在连接表上使用带有属性(列)的 NHibernate ManyToMany (Fluent NHibernate)
我有以下类需要 NHibernate 才能很好地使用。我该怎么做?
public class Customer
{
public int ID { get; set; }
public string Name {get;set;}
}
public class Product
{
public int ID { get; set; }
public string Name {get;set;}
}
public class CustomerPricing
{
public int ID { get; set; }
public decimal Price {get;set;}
public Customer Customer { get; set; }
public Product Product {get;set;}
public datetime ExpiresOn { get; set; }
public string ApprovedBy {get;set;}
}
我正在使用流畅的映射,而 HasManyToMany 对此不起作用(我可以告诉)。我目前正在通过使用 HasMany 然后在模型中执行一些 LINQ 查询来解决这个问题(恶心)。
提前致谢。
凯尔
I have the following classes that I need NHibernate to play nicely with. How do I do it?
public class Customer
{
public int ID { get; set; }
public string Name {get;set;}
}
public class Product
{
public int ID { get; set; }
public string Name {get;set;}
}
public class CustomerPricing
{
public int ID { get; set; }
public decimal Price {get;set;}
public Customer Customer { get; set; }
public Product Product {get;set;}
public datetime ExpiresOn { get; set; }
public string ApprovedBy {get;set;}
}
I am using fluent mappings and the HasManyToMany doesn't work for this (that I can tell). I'm currently working around it by using a HasMany then doing some LINQ queries in the model (yuck).
Thanks in advance.
Kyle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不知道如何在 Fluent 中执行此操作,但因为您将数据存储在连接表中,所以您需要从 CustomerPricing 到 Customer 和 Product 进行多对一。在 hbm.xml 中,CustomerPricing 的映射看起来像这样
,然后在您的 Customer 类(或两者中,如果需要)中添加:
No idea how to do it in Fluent, but because you're storing data in the joining table, you'll need to go Many-to-one from CustomerPricing to both Customer and Product. In an hbm.xml, the mapping for CustomerPricing would look like
Then in your Customer class (or in both, if desired) you'd add:
尝试
使用客户映射为
和产品映射为
Try this
with Customer mapping as
and Product mapping as