Compare column in DataTable without dot and with dot, then CopyToDataTable() linq c#

I have certain column in DataTable where values can be:

Google LTD.
Google LTD

I need to catch them both, because this is potential issue in DataBase. I am able to do it with following code. However I am wondering is there any more efficient way of performing the same?

var IntermediateList = MainProcess.CustomersInLiinos.AsEnumerable()
.Where(g => !string.IsNullOrWhiteSpace(g.Field<string>("SEARCHNAME").Trim()))
.GroupBy(dr => dr.Field<string>("SEARCHNAME").Trim().Replace(".", string.Empty))
.Where(gr => gr.Count() > 1)
.SelectMany(g => g)
.OrderBy(c => c.Field<string>("SEARCHNAME"));

var DotsInSearchName = IntermediateList.AsEnumerable()
.GroupBy(x => x.Field<string>("SEARCHNAME").Trim())
.Where(gr => gr.Count() > 1)
.SelectMany(g => g)
.OrderBy(c => c.Field<string>("SEARCHNAME"));

var result = IntermediateList.Except(DotsInSearchName);

return result.CopyToDataTable();
1 Like

@mrw
when it is only about dots, give a try on following:

group it by removed dot Searchname
filter the group members on Searchname containing no dots
Example on SelectMany, Where combination
grafik

maybe you can ommit 1 statement and the except

var NoDotsInSearchName = IntermediateList.AsEnumerable()
.GroupBy(dr => dr.Field<string>("SEARCHNAME").Trim().Replace(".", string.Empty))
.Where(gr => gr.Count() > 1)
.SelectMany(g => g)
.Where(f => Field<string>("SEARCHNAME").Contains(".")
.OrderBy(c => c.Field<string>("SEARCHNAME"));

Kindly note:

IntermediateList.Except(DotsInSearchName, DataRowComparer.Default);

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.