How can I query using CreateCriteria
over a collection of simple types?
For example, I have 1 class
public class Test
{
public virtual Guid Id { get; set; }
private ICollection<int> _values = new HashedSet<int>();
public virtual ICollection<int> Values
{
get { return _values; }
}
}
And 2 tables to support it:
- Test with only 1 column: Id
- Values with 2 columns: TestId and Value
My goal is to rewrite the following query using CreateCriteria
:
select * from test t
inner join values v on v.TestId = t.Id
where v.Value = 10
I have tried this:
Session.CreateCriteria<Test>("test")
.CreateAlias("test.Values", "values")
.Add(Restrictions.Eq("values", 10))
.List();
Like I would done it with a collection of objects and, obviously, failed. The join is correct but how to add a restriction?