I would like to know the most convenient way (if exists) for storing an entity condition in a parameter, in order to reuse it in every linq where the conditions are.
Suppose a Product object:
public class Product
{
public bool IsDiscontinued { get; set; }
public int UnitsInStock { get; set; }
}
I would like to add the IsOnSale property to the Product class, which contains logic to determine if a product is for sale or not. In this simple example, the logic could be:
IsOnSale = IsDiscontinued == false && UnitsInStock > 0
Then I would have to write a linq query of this type:
from p in context.Products
where p.IsOnSale == true
select p
The goal of the solution is that if in the future the logic will determine whether the product is being sold or not changing (for example, adding the IsBackOrderAllowed property), I do not need to edit linq queries everywhere, but just need to change the IsOnSale property.
here, , -, .