使用值类型列表条件的 nhibernate 查询 [英] nhibernate query using criteria for list of value type

查看:48
本文介绍了使用值类型列表条件的 nhibernate 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类包含整数列表:ICollection;类别枚举

我如何为此创建查询条件?

How I can create a query criteria for that?

我试过了:

List<int> postedCategories = new List<int>{ 1 };
int category = 0;

q.JoinAlias(p => p.CategoryEnum, () => category)
 .AndRestrictionOn(x => category)
   .IsIn(postedCategories);

但是我得到一个 sql 查询WHERE 0 in (1)

but I get a sql query WHERE 0 in (1)

我对对象的集合没有问题,它可以工作,但对 int 的集合不起作用.

I don't have a problem for collecion of object, it works but it doesn't work for collection of int.

这是我映射的一部分:

<set name="CategoryEnum" table="CategoriesEnum">
  <key column="Id"></key>
  <element column="CategoryId" type="int"></element>
</set>

推荐答案

检查这些 Q &答:

Check these Q & A:

你会发现,我们可以通过关键字".elements"

You will find, that we can access element with a keyword ".elements"

Restrictions.In("category.elements", postedCategories)

查询结束:

q.JoinAlias(p => p.CategoryEnum, () => category)
 .Where(Restrictions.In("category.elements", postedCategories))

这篇关于使用值类型列表条件的 nhibernate 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆