Search code examples
c#oracle-databaselinqnhibernatefluent-nhibernate

What part of this Linq query is invalid for nHibernate?


I have a query that resembles the following that I get a NotSupportedException ("Specified method is not supported") for. However, if I execute it at the Distinct() and then perform the rest in memory, all is fine.

MySession.Query<Person>()
  .Where(person => person.StatusId == 1)
  .Select(person => person.Address)
  .Distinct()                     // .ToList() here fixes it.
  .OrderBy(address => address.Addr1)
  .ToList();

Am I doing something illegal for nHibernate's Linq Provider here? If so, any idea how to manipulate this such that I can still run this in a server-side execution-deferred way? Ultimately, my query (Distinct() and everything before that) is abstracted away from my code that performs the OrderBy and ToList.

I'm using:

  • Fluent 1.3.0.733
  • nHibernate 3.3.3.4001
  • odp.net.x64(and86).112.3.0
  • .NET 4.0 Full Framework
  • VS2010

Solution

  • NHibirnate has limitations on using DISTINCT and ORDER BY, http://www.ienablemuch.com/2010/12/performing-order-by-on-distinct-on-linq.html