nhibernate查询使用值类型列表的条件

时间:2015-01-22 16:41:11

标签: c# nhibernate

Class包含int的列表:ICollection<int> CategoryEnum

如何为此创建查询条件?

我试过了:

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

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

但我得到一个SQL查询 (1)

中的0

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

这是我的映射的一部分:

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

1 个答案:

答案 0 :(得分:0)

检查这些Q&amp;答:

您会发现,我们可以使用关键字 ".elements"

来访问元素
Restrictions.In("category.elements", postedCategories)

查询结束:

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