I am using the Linq DynamicQuerable code. I have an array of integers and a string representing the field I want to use as the excluding filter.
For example
IQuerable GetItemsWithoutExcluded(IQuerable qry, string primaryKey, List<int> excludedItems) {
// psuedo code
return qry.Where("p=>! p.primaryKey in excludedItems");
}
Any idea how I would accomplish this using DynamicQuerable?
You can do this without dynamic-LINQ. Dynamic-LINQ is not a full fledged citizen of the framework. And by changing the way you accomplish this task you can use a more effective filter. The way you have it now the method needs to be called for each exclusion.
Try something like this instead
List<int> allKeys = new List<int>{1,2,3,4,5,6};
List<int> excluded = new List<int>{ 1, 2, 3 };
var query = from included in allKeys
where !excluded.Contains(included)
select included;
foreach (var item in query)
Console.WriteLine(item);