Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In terms of performance, I want to do using contains instead of where. How can I create the query below without using contains?
var t=myentities.Employee.WHERE(x=>x.EmployeeID ==123 && myList.Any(y=>x.BranchID.Contains)).ToList();


What I have tried:

var myList=new List<string>();

foreach(var item in Listed)
{ 
    myList.Add(item);
}

var t=myentities.Employee.WHERE(x=>x.EmployeeID ==123 && myList.Any(y=>x.BranchID.Contains)).ToList();
Posted
Updated 16-May-20 7:33am

1 solution

These are not the same thing. Where expects a predicate as argument which is used to filter the items in a collection, and returns a filtered enumeration. Contains expects an item as argument and returns true or false depending on whether the argument is present in the collection.
Moreover, the code block you provided would not even compile since you do not pass any argument to the Contains method (which, actually, you are using as if it were a property). And, if BranchID variable is not a list, it does not have any Contains method either.

Perhaps if you could describe what you are really expecting from your code block, along with the type of variables that you are using, we would be able to propose a concrete solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900