Puneet Gupta Puneet Gupta - 1 year ago 107
C# Question

Retrieving all records where a particular column value can be an item in a list in c# using EF DBSET

I am trying to do this for quite some time but not able to sort it out. Would appreciate if someone knows how to do this...

I am using EntityFramework and I want to retrieve all records from a Table called points where Description field matches any strings in a list...Kind of, try to do something like the below

List<string> someList = new List<string>();
db.Points.Where(m.Description IN someList)

How to achieve this in C# and EF with the right lambda expression ?

Answer Source

You can do something like this:

List<string> someList = new List<string>();
db.Points.Where(m => someList.Contains(m.Description))

Multiple Conditions:

 .Where(m => someList.Contains(m.Description))
 .Where(m => m.someprop == true)


 .Where(m => someList.Contains(m.Description) && m.someprop == true)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download