1

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>

1 Answer 1

1

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.