NHibernate映射集合,不带外键 [英] NHibernate mapping collection without foreign key

查看:123
本文介绍了NHibernate映射集合,不带外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个叫做WorkingDays的类,该类需要一个日期集合,这些日期是银行假期的日期.在我们的数据库中,我们有一个包含这些日期的表-我希望nhibernate获取所有这些日期并填充bankHolidays集合.

I have a class called WorkingDays, this class requires a collection of dates that are the dates of bank holidays. In our database we have a table that contains these dates - I want nhibernate to get all those dates and populate the bankHolidays collection.

但是要注意的是,我没有一个表来表示数据库中的链接-当所有的WorkingDays impls都具有完全相同的银行放假日期列表时,似乎真的没有必要.

The catch is however I do not have a table that represents the link in the database - it seems unnecessary really when all WorkingDays impls will have the exact same list of bank holiday dates.

那么我该如何映射而不需要添加外键?我希望下面的代码能更好地说明问题:

So how can I map this without needing to add a foreign key? I hope the code below can illustrate better:

public class WorkingDays : Interval
{
   public ICollection<DateTime> BankHolidays
   {
       get;
       private set;
   }
}

推荐答案

您是否有理由将其作为实体本身的集合?为什么不由单独的存储库/DAO负责访问此集合?如果数据是相当静态的,那么也可以通过在其上使用二级缓存来获得相当多的收益.

Is there a reason you need this as a collection on the entity itself? Why not have a seperate repository/DAO responsible for accessing this collection? If the data were fairly static, you could probably gain quite a bit by using second level caching on this as well.

这篇关于NHibernate映射集合,不带外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆