Fluent NHibernate 映射不在 PK 领域
我有以下表格,无法编辑它们的结构...
Person
------
Id PK
Code
Name
Order
-----
Id PK
Person_Code
OrderDetails
现在在我的 Person 类中,我想要该人的订单列表,但我不完全确定如何在流畅的 nhibernate 中设置映射以匹配在代码列而不是 ID 上。没有外键约束,我无法更改数据库以使用这些键。我需要这样的东西,但似乎无法弄清楚映射。
public class Person
{
public virtual int Id { get; set; }
public virtual string Code { get; set; }
public virtual IList<Order> Orders { get; private set; }
}
public class Order
{
public virtual int Id { get; set; }
public virtual string OrderDetails { get; set; }
public virtual Person Owner { get; set; }
}
I have the following tables and cannot edit their structure...
Person
------
Id PK
Code
Name
Order
-----
Id PK
Person_Code
OrderDetails
Now in my Person class I want to have a list of Orders for that person, but I'm not entirely sure how to go about setting up the mapping in fluent nhibernate to match on the Code column rather than the ID. There is no foreign key constraint and I am unable to change the database to use the keys. Something like this is what I require, but can;t seem to figure out the mapping.
public class Person
{
public virtual int Id { get; set; }
public virtual string Code { get; set; }
public virtual IList<Order> Orders { get; private set; }
}
public class Order
{
public virtual int Id { get; set; }
public virtual string OrderDetails { get; set; }
public virtual Person Owner { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 KeyColumn 方法定义列。无论是否存在外键约束,它都应该有效。
PropertyRef 方法可从 rev 614 获取,因此您可能需要更新 Fluent nhibernate 版本。
You define your column with the KeyColumn method. It should work regardless of existence of a foreign key constraint.
PropertyRef method is available from rev 614 so you may need to update the fluent nhibernate version.