NHibernate left out join 3 tables
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();
精彩评论