I have a Contact
table in SQL Server, I mapped the table using Entity Framework in my C# console application:
EmployeeId FirstName LastName
--------------------------------
1 Ram Kumar
2 Mohan Raj
3 Aravind Swaamy
4 Ajay Kumar
5 Ram Raj
I need to fetch the records of 1, 3, 5 (EmployeeId
)
Currently I'm doing in the following way
List<Employees> emp = new List<Employees>();
var emp1 = dbContext.Employee.Find(1);
var emp3 = dbContext.Employee.Find(3);
var emp5 = dbContext.Employee.Find(5);
emp.Add(emp1);
emp.Add(emp3);
emp.Add(emp5);
Kindly assist me how to get list of records using Find
method by passing a list of primary key values.
Some people thinking the question is duplicate of How to do an "in" query in entity framework?. No it's absolutely wrong. My question is how to fetch multiple records using Find
extension method. Because IN
operation perform slower than the Find
operation.