将属性映射到NHibernate中另一个表中的字段 [英] Mapping a property to a field from another table in NHibernate
本文介绍了将属性映射到NHibernate中另一个表中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下类:
consider the following class:
class Order {
int OrderId {get; set;}
int CustomerId {get; set;}
string CustomerName {get; set;}
//other fields go here
}
映射订单表。是否有可能通过外键关系将属性CustomerName映射到Customers表?
which is mapped to Orders table. Is it possible to map the property CustomerName to the Customers table through the foreign key relation?
推荐答案
是的,您可以使用<一个href =http://ayende.com/Blog/archive/2009/04/20/nhibernate-mapping-ltjoingt.aspx =nofollow noreferrer>加入映射元素。另一种选择是映射视图而不是表格。但如果可能的话,您应该采用面向对象的方法,并映射Order和Customer之间的多对多关系。
Yes, you can use the join mapping element for this. Another option is to map a view instead of a table. But if possible you should take the object-oriented approach and map the many-to-many relationship between Order and Customer.
这篇关于将属性映射到NHibernate中另一个表中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文