开发者

NHibernate left out join 3 tables

开发者 https://www.devze.com 2023-03-11 00:35 出处:网络
I have 3 entities setup in nhibernate, user, album, photo. User HasMany Albums Album HasMany Photo I am trying to write a query in NHibernate that pretty much does the following sql query.

I have 3 entities setup in nhibernate, user, album, photo. User HasMany Albums Album HasMany Photo

I am trying to write a query in NHibernate that pretty much does the following sql query. I want the result to be a List<Photo>

Can anyone give me a su开发者_开发技巧ggestion on how that can be done?

thanks

select p.* from UserTbl u
Left outer join Album a
on u.Id = a.UserId
left outer join Photo p
on a.Id = p.AlbumId
where u.Email = 'myemail@email.com'


I don't see why you need left joins there if you are starting from User and retrieving Photo.

One possibility:

IList<Photo> results =
    session.Query<Photo>()
           .Where(x => x.Album.User.Email = 'myemail@email.com')
           .ToList();
0

精彩评论

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