Is there a better way to write this CONTAINS from an ARRAY?
I am passing a string/array into my LINQ statement. In SQL the code that is working is
SELECT * FROM dbo.option1
WHERE option1Code IN ('9841','V237','SV02','2057')
In EF using LINQ I am trying
using (var ctx = new ProductEntities())
{
//--------------------------------------------------------------------//
string csvSKU = '984,237,102,207';
string[] mArray = csvSKU.Split(',');
var results = (from o in ctx.option1
join p in ctx.Products on o.option1Code equals p.productSKU
where mArray.Contains(o.option1Code)
orderby o.option1Sort
select o).Distinct().ToList();
return results;
}
This looks perfectly fine and should result in similar SQL as you posted (at least for the
Containspart).Also not really sure what your join is for right now – are there any option codes that have no entry in the
Productstable /productSKU?