Reputation: 1742
I am getting from the client a list of strings (items he chose), and now I need to return results from the database. The client request is:
List<string> campaignStrings
List examples:
[0] - "292 | Mac/June 17"
[1] - "161 | Direct/June 17"
The way I am trying, without success, is:
var campaigns = ctx.V_CommercialCampaigns.Where(cam => campaignStrings.Any(x => cam.Name.Contains(x))).Select(id => id.Id).ToList();
I am using "Contains" because "Name" column might not be identical to the search terms.
What am I doing wrong?
Upvotes: 1
Views: 348
Reputation: 1607
try with this solution
var campaigns = ctx.V_CommercialCampaigns.Where(cam => campaignStrings.Contains((cam))).Select(id => id.Id).ToList();
Upvotes: 1
Reputation: 3810
If you want to check whether cam.Name
occurs in campaignStrings
list, then you need to change where
clause to this:
.Where(cam => campaignStrings.Any(x => x.Contains(cam.Name)))
Upvotes: 2