I am having a list of model which i populated with items. The below list is populated with items :-
List<Entry> list = new List<Entry>
{
new Entry { EmployeeId = 1, EntryDate = '2016-11-01', InDate = '2016-11-01' },
new Entry { EmployeeId = 1, EntryDate = '2016-11-05', InDate = '2016-11-05' },
new Entry { EmployeeId = 2, EntryDate = '2016-11-01', InDate = '2016-11-01' }
};
Now I want to query a table Entry
from database in a such a way that records should be matching with the above List with EmployeeId
& EntryDate
as parameter.
Entry table has same columns as in the code above.
If it was one field i can use contains
but for multiple fields what should i do?
My results from database table should match the above List with 2 Columns matching EmployeeId
& EntryDate
.
Logically, what you want is:
var query = db.Table.Where(e => list.Any(le => e.EmployeeId == le.EmployeeId &&
e.EntryDate == le.EntryDate));
I don't know whether that will work with Entity Framework, but it's worth a try. (It would be fine in LINQ to Objects, for example.)
See more on this question at Stackoverflow