Reputation: 1775
Here is my code:
string[] customerNames = searchModel.CustomerName.Split(',');
query = query.Where(d => customerNames.Contains(d.CustomerName, comparer) || customerNames.Contains(d.Company1.CompanyName, comparer));
Which works if you are just looking for exact matches. However I'd like to partial match, ie: if customerNames contains an element 'ell'
, it would select d if d.CustomerName
was 'Hello'
since 'ell' is in 'Hello'
I tried overriding the EqualityComparer, but I believe it is trying to use the GetHashCode
function rather than the Equals
in the Comparer, which I'm not sure how to implement.
How should I go about this?
Upvotes: 0
Views: 1511
Reputation: 125620
string[] customerNames = searchModel.CustomerName.Split(',');
query = query.Where(d => customerNames.Any(c => c.Contains(d.CustomerName)) || customerNames.Any(c => c.Contains(d.Company1.CompanyName)));
But you should be aware, that it may get really slow when customerNames
has a lot of items.
Upvotes: 1