开发者

newbie Nhibernate join query in a DetachedCriteria

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 开发者_Python百科to a DetachedCriteria?


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜