Marta Nocoń
Marta Nocoń

Reputation: 13

nhibernate query using criteria for list of value type

Class contains List of int: ICollection<int> CategoryEnum

How I can create a query criteria for that?

I tried:

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

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

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

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

This is part of my mapping:

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

Upvotes: 1

Views: 1635

Answers (1)

Radim K&#246;hler
Radim K&#246;hler

Reputation: 123861

Check these Q & A:

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

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

with query over:

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

Upvotes: 1

Related Questions