tags:

views:

23

answers:

1

Hello SO Gus,

This is a quick one!

I've tried the latest v3.0.0 alpha and that overload of distinct is still not supported, however the parameterless overload (which uses the default equality comparer) is supported. Does anyone know when will this be supported in Nhibernate.Linq? Also is there any other Linq providers for NHibernate other than NHibernate.Linq?


Any help appreciated!

A: 

NHibernate can't possibly use any arbitrary IEqualityComparer and translate that to SQL. For example:

class PersonEqualityComparer: IEqualityComparer<Person> {
  public bool Equals(Person p1, Person p2) {
    var cfg = ConfigurationManager.AppSettings["something"];
    if (SomeStaticClass.SomeMethod(cfg)) {
      return p1.Id == p2.Id;
    }
    return p1.Name == p2.Name;
  }

  public int GetHashCode(Person p) {
    return p.Id.GetHashCode();
  }
}

Yes, it might be a horrible implementation, but possible and perfectly valid. How would NHibernate translate that to SQL? It can't, or at least not without some help, so you need to extend the NHibernate LINQ provider to tell NHibernate how to translate it.

Mauricio Scheffer
Yeah, I was specifically asking when would someone implement this! I'm aware that I can extend the Linq provider and add the support for it myself, but thanks anyway!
Galilyou
@Galilyou: in case my answer wasn't clear: there is no way NHibernate (or any other LINQ provider (except for LINQ-to-objects), dare I say) can possibly support any arbitrary IEqualityComparer, *ever*.
Mauricio Scheffer
To rephrase Mauricio's answer: IEqualityComparer doesn't make ANY sense in a LINQ-to-AnythingOtherThanObjects.
Diego Mijelshon