Tutorial :LINQ Query to filter DTO



Question:

I have an array...and I need to exclude all the items in this array of string from the masterList.customField as shown below

string[] excludeItem = {"a","b","c"};    CustomDTO[] masterList = service.LoadMasterList();    masterList.Where(c=> masterList.customField NOT IN excludeItem  

How do I achieve the NOT IN part above?


Solution:1

Assuming customField is a string:

masterList.Where(c => !excludeItem.Contains(c.customField));  


Solution:2

Or, as a LINQ query:

var x = from c in masterList          where !excludedItem.Contains(c.CustomField)          select c;  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »