I'm testing out nhibernate 3 CR, but fails to create the following SQL using Linq:
select *
from Users as {user}
inner join Test as test on test.UserId = user.Id
inner join Release as release on release.TestId = test.TestId
where Release.Status = 1
order by count(release.Status) desc;
I have not got so far, my current code is like this and gives me something complete different:
var users = from user in Session.Query<User>()
join test in Session.Query<Test>() on user.Id equals test.User.Id
join release in Session.Query<Release>() on test.Id equals release.Test.Id
where release.Status == 1
orderby release.Status
descending
select user;
Is there any resources on how to use inner joins with linq? And what should I do with:
order by count(release.Status)
Is this something that should be done with QueryOver instead?
First, define relationships in your model instead of trying to join by id.
Then you'll be able to do this:
from release in session.Query<Release>()
where release.Status == 1
select release.Test.User
All that's missing is the orderby, which I don't think is correct (you are trying to order by an aggregate, but you're not specifying a group by)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With