views:

16

answers:

1

I have a domain like this:

class Project
{
...
Unit ProjectUnit
}

class Unit
{
...
IList<User> Users
}

class User
{
...

}

I have to get all projects based on one user, so: each Project where Unit.Users contain query user.

How can I translate this to a DetachedCriteria?

A: 

This assumes you have an Id property on your User class and you're passing in a User user.

DetachedCriteria query = DetachedCriteria.For(typeof(Project),"Project")
                            .CreateCriteria("ProjectUnit","Unit")
                            .CreateCriteria("Users","users")
                            .Add(Expression.Eq("Id", user.Id));
Chris Conway