Comparing multiple entity properties against list of entities
- by roosteronacid
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.