c# - Use LINQ to find duplicated rows (with list of specified columns) -


i use code below duplicated rows 3 columns: string, date, money. wonder if there general method can input dynamic list of column name in linq find duplicated rows?

datatable allduplicates = dt.asenumerable()     .groupby(dr => new     {          field1 = dr.field<object>("string"),          field2 = dr.field<object>("date"),          field3 = dr.field<object>("money"),      })     .where(g => g.count() > 1)     .selectmany(g => g)     .tolist().copytodatatable(); } 

how custom arrayequalitycomparer<t> type (such 1 listed here):

string[] colstoconsider = ...  var allduplicates = dt.asenumerable()                       .groupby(dr => colstoconsider.select(dr.field<object>)                                                    .toarray(),                                new arrayequalitycomparer<object>())                              .where(g => g.count() > 1)                       .selectmany(g => g)                       .copytodatatable(); 

you can consider using dictionary<tkey, tvalue> (and associated dictionary-comparer) if find implicit use of array indices here hackish.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -