Linq2NHibernate - Only Left Joins?
Really quick question..
Does Linq2NHibernate always create a left join to retrieve relationships? 开发者_如何学CIs there a way that I can get an inner one instead?
Thank you in advance.
Filipe
As far as I know.
For any relationship that is not One-to-One, NHibernate makes the assumption that the relationship could have 0 to many results, thus uses a Left Join.
I don't know about Linq2NHibernate, but in NH3 using QueryOver API you can specify the join types.
For example, give a Product with a Category. If you wrote:
var result = Session.QueryOver<Product>()
.Fetch(x => x.Category).Eager
.List();
This will result in a left join, if you wanted to specify an inner join you could write the same query as:
var result = Session.QueryOver<Product>()
.JoinQueryOver(x => x.Category, JoinType.InnerJoin)
.List();
This will result in an Inner Join.
As far as I know you can't specify join types when using the LINQ provider (Query<T>
in NH3)
精彩评论