Is it possible to store the Where clause in this linq expression in a variable?
Func<NutritionValues, bool> condition;
if (isBarcode)
condition = f => f.barcode == name;
else
condition = f => f.food == name;
var foods = context.NutritionValues.Where(condition).
Select(f => new SerializableFood
{
Name = f.food,
Calories = f.energy_kcal,
Carbohydrates = f.carbohydrates,
Fats = f.fats,
Proteins = f.protiens
});
The condition is 100% right. If I write the condition f => f.barcode == namedirectly to the Where function, this works, but it doesnโt. This code returns an empty set. Please do you know why?
source
share