nHibernate - 一个仅包含超类型的集合
我有以下类:
class Employee
{
public string Name { get; set; }
}
class HistoricalEmployee : Employee
{
public DateTime TerminationDate { get; set; }
}
class Company
{
public IList<Person> CurrentEmployees { get; set; }
}
Employee 和 HistoricalEmployee 使用每类表层次结构策略进行映射。
当我检索 CurrentEmployees 集合时,我希望它只包含 Employee 元素,而不是 HistoricalEmployees 元素。
当员工“死亡”时,他们并没有真正被删除,
但他们变成了 HistoricalEmployee(具有更多属性,例如终止日期等)。
显然,随着时间的推移,HistoricalEmployees 的数量将超过Employees 的数量,
因此,当我只需要当前的Employees 时,我无法获取所有HistoricalEmployees。
如何(流畅地)将集合配置为仅检索超类的元素?
我认为这与多态性属性有关,但我无法真正弄清楚如何做到这一点。
谢谢,
强尼
I have the following classes:
class Employee
{
public string Name { get; set; }
}
class HistoricalEmployee : Employee
{
public DateTime TerminationDate { get; set; }
}
class Company
{
public IList<Person> CurrentEmployees { get; set; }
}
Employee and HistoricalEmployee are mapped using table-per-class-heirarchy strategy.
When I retrieve the CurrentEmployees collection, I want it only to contain elements that are Employee, and NOT HistoricalEmployees.
when an employee 'dies', they're not really deleted,
but they become HistoricalEmployee (with a few more attributes, such as termination date etc.).
Obviously, over time, the number of HistoricalEmployees will exceed the number of Employees by magnitudes,
so I can't fetch all HistoricalEmployees when I only need current Employees.
How can I (fluently) configure the collection to only retrieve elements of the super class?
I think it's something to do with the Polymorphism property, but I couldn't really figure out how to do that.
thanks,
Jhonny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我这样做了:
显然,.Where() 函数在属性上创建了一个过滤器,这正是我所需要的。
请注意,我使用了字符串版本,并注释掉了 Func<>版本。
这是因为据我所知,目前(FNH 1.1)Func<>版本不起作用。
希望这对某人有帮助,
J
Ok, I did this like so:
apparently, the .Where() function creates a filter on the property, which is exactly what I needed.
notice that I used the string version, and commented-out the Func<> version.
This is because that currently (FNH 1.1), as far as I could determine, the Func<> version doesn't work.
hopes this helps somebody,
J