c# - Use tuples with Entity Framework Contains statement -


i have entity reference composite of identifier , environment. want implement function allow user pass list of tuples of (id, environment) , return required entities. possible use contains() in such scenarios? how? simple reference, simple as

model.myentities.where(e => myids.contains(e.id)) 

edit: clarify, not looking how use contains() method retrieve list of ids; line wrote above this. looking able retrieve list of entities matching tuples of (id, environment) rather id.

latest version of entity framework allows contains on array of primitive types (i think works on ienumerable now, haven't tried).

if match solely on id (ie, match if 1 of tuple's id myentity.id, work (i'm using tuple losely here case seems actual object; tuple has itemn properties):

var containedids = yourlistoftuples.select(t => t.id).toarray(); model.myentities.where(e => containedids.contains(e.id)); 

this translate where ... in ([the ids in containedids]) statement in sql.


Comments