Reputation: 458
I have a table in database called Products and which has a column name called LaunchYear(int) data type.I want to filter the table using a CSV list of Launch Years.
listCSVLaunchYear= "5,7,8";
I want help to create a LINQ to Entity query which will return me all products in CSV list. I tried using contains but that did not work. Any help will appreciated.
Upvotes: 1
Views: 101
Reputation: 205769
You need first to convert the CSV list to underlying column data type list and then use Contains
, like this
var launchYears = listCSVLaunchYear.Split(',').Select(x => int.Parse(x)).ToList();
var query = db.Products.Where(p => launchYears.Contains(p.LaunchYear));
Upvotes: 1