c# - Override EqualityComparer for LINQ to SQL class -


i want override equalitycomparer 1 of linq sql classes (autogenerated visual studio) when match indexof, use comparison instead of whatever class. not seem work, , override not called.

here logic comparison:

clientfilelist f = new clientfilelist(); f.clientid = -1 * lines; f.jobid = jobid; f.drscode = aparts[0]; f.documentnumber = aparts[1]; f.revision = aparts[2]; f.title = aparts[3]; f.titleline2 = aparts[4]; f.titleline3 = aparts[5]; f.sheetnumber = aparts[6]; f.status = aparts[7]; f.colorcode = colorcode;  if(ocfile.indexof(f)==-1) {     // element not duplicate     ocfile.add(f); } 

and here extended class override equalitycomparer:

public partial class clientfilelist : equalitycomparer<clientfilelist> {     public override bool equals(clientfilelist x, clientfilelist y)     {         //throw new notimplementedexception();         return (x.documentnumber == y.documentnumber &&                 x.revision == y.revision);     }      public override int gethashcode(clientfilelist obj)     {         string s = obj.documentnumber + obj.revision;         return s.gethashcode();         //throw new notimplementedexception();     } } 

what hoping if document matching documentnumber , revision in database, don't want add again (this implemented while reading delimited text file , inserting database). msdn documentation on indexof seemed indicate use equalitycomparer . . . not seeing behavior. doing wrong?

i want override equalitycomparer 1 of linq sql classes

i don't think do. think want override equals method, , implement iequatable<t>. equalitycomparer meant object able compare objects of other types - example agecomparer might derive equalitycomparer<person>.

if override equals(object) , gethashcode, , implement iequatable<t>, i'd expect indexof work, assuming ocfile list<clientfilelist> or similar (you haven't told us). however, won't affect how linq sql issues queries, of course.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -