I think NH shouldn't try and mix-up custom functions and generated SQL.

I agree that the correct thing to do is force the developer to move any custom functions that LINQ is not aware of after a .ToList() to make it clear what's happening in memory (Linq2Objects), and what's getting executed as SQL.

-----Original Message----- From: cremor
Sent: Friday, January 13, 2012 2:35 PM
To: nhibernate-development
Subject: [nhibernate-development] Re: Linq Distinct() and projection using custom methods

I've never worked with Linq2EF or Linq2SQL, but I'd expect *exactly*
the cases you described for Linq2EF in the pull request. It's just the
most logical way to handle all these cases.

So for this question in particular:
I'd expect an exception because Transform() is a unknown function. I'd
then add a ToArray() or ToList() before Select() and everything would
be fine.

On 13 Jan., 14:42, Oskar Berggren <[email protected]> wrote:
Consider something like

OrderDto[] result = db.Orders
                                .Select(x => new OrderDto
                                                                 {

ShippingDate = Transform(x.ShippingDate),

OrderDate = Transform(x.OrderDate)
                                                                 })
                                .Distinct()
                                .ToArray();

Entity Framework does not support the above, since they don't allow
use of custom methods.
Linq2SQL accepts the above by passing DISTINCT in the SQL. The
transform method isn't called until afterward - e.i the result of the
Transform() is not used to calculate the distinctness.
Linq2Objects will of course execute the Distinct() AFTER Transform().

So question is... what should NH do? The pull requesthttps://github.com/nhibernate/nhibernate-core/pull/41implements this
so it works like L2SQL.

The behaviour of L2SQL can certainly be convenient for cases where the
transformation does not affect the uniqueness, but can also be
surprising for cases where it does matter.

/Oskar

Reply via email to