Filter LINQ to entities query based on 2 dimensional array
This is a Linq2entities challenge...
I have an entity (ID, CategoryID, Value) and a 2 dim开发者_JS百科ensional int array with CategoryID / Value pairs. I need to get all entities filtered by each pair, something like:
from e in Entity
where (e.CategoryID and e.Value) in array
select e;
So basically is a "two linked fields" filter.
A dirty solution would be to concat and compare, like:
concatarray = some function to concat CategoryID + "/" + Value;
from e in Entity
where e.CategoryID + "/" + e.Value in concatarray
select e;
but I don't want to use this because of performance issues.
Any idea?
Thanks a lot!
First, I would convert your array into list of objects with specific properties. Using 2d array for this is not good idea.
Then the query, might not be translatable to SQL in EF.
from e in Entity
where array.Where(a=>a.CategoryID == e.CategoryID && a.Value == e.Value).Any()
select e
精彩评论