开发者

NHibernate Linq - why does it use join when querying foreign key field?

开发者 https://www.devze.com 2023-01-10 23:26 出处:网络
I have a object model a bit like this: public class Foo { public int Id {get;set;} public string FooName {get;set;}

I have a object model a bit like this:

public class Foo
{
  public int Id {get;set;}
  public string FooName {get;set;}
}

public class Bar
{
  public int Id {get;set;}
  public Foo Foo {get;set;}
}

These correspond to tables in the database in the typical one-to-many kind of way.

Using Linq to NHibernate to query Bars according to thei开发者_开发问答r Foo.Id property (which should simply query the FoodId foreign key in the Bars table) produces SQL with a join!

Does anyone know why this is so? Is this standard NHibernate behaviour? Or something to do with the Linq provider? Or maybe even FluentNHibernate (which I'm using for mapping)?

Thanks

David


This behavior is caused by NHibernate.Linq (I believe it relates to the way that the expression is converted into an ICriteria representation of the query). As far as I know, there's no way around this using Nhibernate.Linq directly, but you could achieve the results that you're looking for by using HQL or ICriteria directly.

0

精彩评论

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

关注公众号