why does it use join when querying foreign key field?

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 their 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.

链接地址: http://www.djcxy.com/p/60986.html

上一篇: 流利NHibernate加入属性值

下一篇: 为什么在查询外键字段时使用连接?