尝试使用QueryOver和标记的枚举查询。这适用于Nhibernate.Linq:
var results = repo.Query()
.Where(x => (x.Classification & LineItemClassification.Shipping) == LineItemClassification.Shipping);
使用QueryOver抛出Could not determine member from (Convert(x.Classification) & 2)
:
var results = repo.QueryOver()
.Where(x => (x.Classification & LineItemClassification.Shipping) == LineItemClassification.Shipping);
有什么想法吗?建议?
枚举:
[Flags]
public enum LineItemClassification
{
Foo,
Widget,
Shipping
}
映射:
Map(x => x.Classification)
.CustomType<LineItemClassification>();
答案 0 :(得分:3)
我今天遇到了类似的问题,最后做了一个SQL投影。不太理想,因为它让我们远离了QueryOver API带来的类型安全性,但它确实有效。我的代码的相关部分如下。
.QueryOver<ProjectActivity>()
.Where(Expression.Gt(Projections.SqlProjection(String.Format("({{alias}}.ProjectActivityTypeId & {0}) as ProjectActivityTypeId", (int)type), null, null), 0))
希望有所帮助。