老赵, I think the current version of NHibernate.Linq not use it in a
production environment, if the two ways for writing the generated SQL is the
same, and has been the object is different, then the problem is the Linq

2009/8/15 Jeffrey Zhao <[email protected]>

>  Hello, I met a problem when use NHibernate.Linq to get single entity with
> eager load. For example I've a the models like:
>
> public class Product { ... }
> public class Product
> {
>     public virtual int ProductID { get; set; }
>     public virtual string Name { get; set; }
>     public virtual ISet<Property> Properties { get; set; } // lazy load by
> default.
> }
>
>
> That's simple. When I try to load the single Product with id equals 1
> eagerly:
>
> var product = session
>     .CreateCriteria(typeof(Product))
>     .Add(Expression.IdEq(1))
>     .SetFetchMode("Properties", FetchMode.Eager)
>     .UniqueResult<Product>();
>
>
> This works pretty fine (a Product instance contains 2 Property instances),
> but when I want to use NHibernate.Linq to do the same thing:
>
> var product = session.Linq<Product>().Expand("Properties").Single(p =>
> p.ProductID == 1);
>
>
> It throws an exception with message "Sequence contains more than one
> element". The problem still exists if I use ".Where(p => p.ProductID =
> 1).Single()", then I simply tried to use "First" instead of "Single". No
> exception throwed but I got a Product instance contains _only 1_ Property
> instance - it should be 2 actually.
>
> But the interesting thing is, with the help of SQL Profiler, I found that
> the SQL queries generated by Criteria API and LINQ are just the same - seems
> like a bug in NHibernate.Linq?
>
>
>
> Blog: http://www.cnblogs.com/JeffreyZhao/
> Twitter: http://twitter.com/jeffz_cn
>
> >
>


-- 
江名峰
msn:[email protected]

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

Reply via email to