开发者

newbie Nhibernate join query in a DetachedCriteria

开发者 https://www.devze.com 2023-01-19 09:47 出处:网络
I have a domain like this: class Project { ... Unit ProjectUnit } class Unit { ... IList<User> Users } class User

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

精彩评论

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