Fluent NHibernate:没有外键的映射属性?
我有这两个类:
public class Parent
{
public virtual string Name { get; set; }
public virtual string Family_id { get; set; }
}
public class Children
{
public virtual string Name { get; set; }
public virtual DateTime BirthDate { get; set; }
public virtual string Family_id { get; set; }
}
当我获取父级时,我还想获取与父级具有相同 Family_id 的最年长(按出生日期排序)的子级。
数据库中的父级和子级之间没有外键。
(我不想使用两个不同的存储库,我想要映射中的功能)
我可以使用 property-ref 吗?
I have these two classes:
public class Parent
{
public virtual string Name { get; set; }
public virtual string Family_id { get; set; }
}
public class Children
{
public virtual string Name { get; set; }
public virtual DateTime BirthDate { get; set; }
public virtual string Family_id { get; set; }
}
When I fetch a parent, I also want to fetch the oldest (ordered by BirthDate) children that has the same Family_id as the parent.
There is no foreign key between the parent and the children in the database.
(I do not want to use two different repositories, I want the functionality in the mappings)
Is property-ref something I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种策略是对 Children 集合强制急切加载,并创建另一个属性来获取最大的孩子。
Property-Ref 用于使用非主键的列连接到另一个表。
另一种可能性是向父表 (OldestChild_FK) 添加一列,然后从子表中加入该行。
One strategy would be to force an Eager Load on a Children collection and create another property to get the oldest child.
Property-Ref is used to join to another table using a column which is not the primary key.
Another possibility would be to add a column to the Parent table (OldestChild_FK) and then join in that row from the Children table.
我认为您想要做的是在父级上创建一个名为 OldestChild 的属性或最古老的子级列表,并忽略该属性并编写一些自定义查询(HQL 或 SQL)以返回您想要的结果。
这里是一个关于忽略的线程FluentNhibernate 中的属性。
I think what you want to do is create a property on the Parent called OldestChild or a list of Oldest Children and ignore that property and write some custom query (HQL or SQL) to return the results you want.
Here is a thread on ignoring properties in FluentNhibernate.