Reputation: 13
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
Reputation: 123861
Check these Q & A:
IList<string>
property?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