Nhibernate QueryOver枚举标志

mxm*_*ile 6 nhibernate queryover

尝试使用QueryOver和标记的枚举查询.这适用于Nhibernate.Linq:

var results = repo.Query()
  .Where(x => (x.Classification & LineItemClassification.Shipping) == LineItemClassification.Shipping);
Run Code Online (Sandbox Code Playgroud)

这将Could not determine member from (Convert(x.Classification) & 2)使用QueryOver 抛出:

 var results = repo.QueryOver()
   .Where(x => (x.Classification & LineItemClassification.Shipping) == LineItemClassification.Shipping);
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?建议?

枚举:

[Flags]
public enum LineItemClassification
{
        Foo,
        Widget,
        Shipping
}
Run Code Online (Sandbox Code Playgroud)

制图:

Map(x => x.Classification)
  .CustomType<LineItemClassification>();
Run Code Online (Sandbox Code Playgroud)

csa*_*ano 3

我今天遇到了类似的问题,最后做了一个 SQL 投影。这并不理想,因为它使我们远离了 QueryOver API 所获得的类型安全性,但它确实有效。我的代码的相关部分如下。

.QueryOver<ProjectActivity>()
.Where(Expression.Gt(Projections.SqlProjection(String.Format("({{alias}}.ProjectActivityTypeId & {0}) as ProjectActivityTypeId", (int)type), null, null), 0))
Run Code Online (Sandbox Code Playgroud)

希望有帮助。