Nhibernate QueryOver 通过枚举标志
我通过 QueryOver 进行查询:
public IList<Person> SearchTest(PersonEnumType type)
{
var q = SessionInstance.QueryOver<Person>();
q = q.Where(x => (x.PersonEnumType & type) == type);
return q.List<Person>();
}
并且 PersonEnumType
是一个枚举标志:
[Flags]
public enum PersonEnumType
{
Employee1 = 1,
Employee2 = 2,
Employee3 = 4
}
这会抛出 Could not certain member from (Convert(x.PersonEnumType) & Convert(value(NHibernate.Repository.PersonRepositoryNh+) <>c__DisplayClass2).type))
当然,这在 Nhibernate.Linq 中有效。
为什么?
I have a query by QueryOver :
public IList<Person> SearchTest(PersonEnumType type)
{
var q = SessionInstance.QueryOver<Person>();
q = q.Where(x => (x.PersonEnumType & type) == type);
return q.List<Person>();
}
and PersonEnumType
is a Enum flags :
[Flags]
public enum PersonEnumType
{
Employee1 = 1,
Employee2 = 2,
Employee3 = 4
}
This throws Could not determine member from (Convert(x.PersonEnumType) & Convert(value(NHibernate.Repository.PersonRepositoryNh+<>c__DisplayClass2).type))
Of course this works in Nhibernate.Linq.
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已在映射文件中正确映射您的属性:
您可以使用过滤器实现您正在寻找的内容。
我不知道这是否是唯一的解决方案,但是,这里是:
您可以创建过滤器定义:
并在类映射中实现它:
现在您可以打开过滤器:
您可以阅读有关过滤器的更多信息 此处。
if you've mapped your property properly in your mapping file:
You can achieve what you're looking for using filters.
I don't know if this is the only solution but, here it goes:
You can create a filter definition:
and implement it in your class mapping:
Now you can switch on your filter:
You can read more about filters here.