Comparing multiple entity properties against list of entities
Posted
by roosteronacid
on Stack Overflow
See other posts from Stack Overflow
or by roosteronacid
Published on 2010-04-09T07:37:27Z
Indexed on
2010/04/09
7:43 UTC
Read the original article
Hit count: 441
Consider this snippet of code:
var iList = new List<Entities.Ingredient>
{
new Entities.Ingredient { Name = "tomato", Amount = 2.0 },
new Entities.Ingredient { Name = "cheese", Amount = 100.0 }
};
var matches = new DataContext().Ingredients.Where(i => Comparer(i, iList));
private Boolean Comparer(Entities.Ingredient i, List<Entities.Ingredient> iList)
{
foreach (var i in iList)
{
if (i.Name == iList.Name && i.Amount >= iList.Amount) return true;
}
return false;
}
Is there a more efficient way of doing this? Preferably without being too verbose; from x in y select z... If thats at all possible.
© Stack Overflow or respective owner