Hello -- I have an "Order" class which has a many-to-one relationship
OrderedBy to a "Customer" class (picture Northwind).  Now I tell the
Order mapping to outer-join="true" the OrderedBy relationship, which
works fine using the criteria and query over methods.  However, when
using the new NHibernate.Linq Query<T>(), the outer-join="true" is
ignored, resulting in a select N+1 scenario (selecting one customer
for each call to order.OrderedBy).  If I use the Fetch() extension
(redundantly), then the fetch occurs, but (1) I would like to specify
the join in my mapping, and (2) Fetch does not work in my scenario
since i need to later order the query (which breaks fetch).

Now before upgrading to NHibernate 3.0Alpha2, the old NHibernate.Linq
provider would respect the join properly (probably because it used the
criteria API), but after the upgrade my old code is broken by this
behavior (causing N+1 everwhere).

So my mapping is basically:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class
    name="NH3SampleWeb.Models.Order, NH3SampleWeb"
    table="Orders" >
    <id name="Id" column="OrderID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="OrderDate" />
    <property name="ShipAddress" />

    <many-to-one name="OrderedBy" column="CustomerID"
class="NH3SampleWeb.Models.Customer, NH3SampleWeb" outer-join="true"></
many-to-one>

  </class>
</hibernate-mapping>

And an example of the divergent query behavior
//Query NHibernate.Linq provider ignores the outer-join (19 queries)
var orders =
ExampleApplication.GetCurrentSession().Query<Order>().OrderBy(x=>x.OrderDate).Take(20).ToList();

//QueryOver uses the outer-join correctly (1 query)
var orders =
ExampleApplication.GetCurrentSession().QueryOver<Order>().OrderBy(x=>x.OrderDate).Asc.Take(20).List();

Now those two queries look almost exactly the same but the Linq one
produces 19 queries, while queryOver does just one query.  Any help
you would offer would be appreciated, and I can post the entire source
if necessary.

Thanks,

Scott

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to