Nhibernate QueryOver 枚举标志

标签 nhibernate queryover

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

var results = repo.Query()
  .Where(x => (x.Classification & LineItemClassification.Shipping) == LineItemClassification.Shipping);

这会抛出 Could not determine member from (Convert(x.Classification) & 2)使用 QueryOver:
 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>();

最佳答案

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

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

希望有帮助。

关于Nhibernate QueryOver 枚举标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5557915/

相关文章:

nhibernate - QueryOver 语句以 DateTime 降序选择 N 行

NHibernate QueryOver distinct

.net - 在 NHibernate 上使用 QueryOver 限制 child 计数

Nhibernate QueryOver 在 Eager Fetch 中使用别名

c# - 通过 DI 配置 Envers RevisionListener

c# - 这是什么属性(property)?有必要吗?

c# - QueryOver 上的 GroupBy SqlFunction

hibernate - 查看 NHibernate session 对象

NHibernate QueryOver 关联不包含项目

nhibernate - QueryOver - 如何从三个表的联接中仅选择一个对象