在使用继承属性的lambda的Fluent NHibernate映射中应用过滤器? [英] Applying a filter in a Fluent NHibernate mapping using a lambda referencing an inherited property?
问题描述
是否有任何方法可以在流畅的nhibernate映射文件中指定仅将条件有条件地拉入业务实体的方法?
Is there any way to specify in a fluent nhibernate mapping file a way to only conditionally pull values into a business entity?
我当前的映射片段是:
HasMany(m => m.GroupUsers)
.Table("GroupUsers")
.KeyColumns.Add("UserEntityId")
.Inverse()
.Cascade.All();
理想情况下,我想要这个(它可以编译但会抛出一个未定义gu的运行时错误):
Ideally, I'd like to have this (which compiles but throws a runtime error that gu isn't defined):
HasMany(m => m.GroupUsers)
.Table("GroupUsers")
.KeyColumns.Add("UserEntityId")
.Where(gu => gu.DeleteDate == null)
.Inverse()
.Cascade.All();
问题的症结在于,我希望映射仅撤回那些删除日期为空的组用户条目.
The crux of the issue is that I'd like the mapping to only pull back those group users entries with a null delete date.
删除日期在基类上
推荐答案
From the FluentNhibernate API documentation:
T Where(Expression>哪里)
T Where(Expression> where)
为此一对多关系设置where子句.注意:这个仅支持简单情况,对于更复杂的情况,请使用字符串重载条款.
Sets the where clause for this one-to-many relationship. Note: This only supports simple cases, use the string overload for more complex clauses.
对基类属性的过滤似乎属于复杂"情况.
It seems filtering for base class properties is belongs to the "complex" cases.
因此,您应该使用 Where(String)
重载(我尚未测试语法...):
So you should use the Where(String)
overload (I haven't tested the syntax...):
HasMany(m => m.GroupUsers)
.Table("GroupUsers")
.KeyColumns.Add("UserEntityId")
.Where("DeleteDate is null")
.Inverse()
.Cascade.All();
这篇关于在使用继承属性的lambda的Fluent NHibernate映射中应用过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!