c# Lambda 表达式

OR

Expression<Func<Inventory, bool>> expression = c => 1 == 1;
Expression<Func<Inventory, bool>> expression1 = c => cnPlants.Contains(c.Plant) && (c.StorageLocation == "4000" || c.StorageLocation == "2400");
Expression<Func<Inventory, bool>> expression2 = c => c.Plant == "CN16" && (c.StorageLocation == "4000" || c.StorageLocation == "2400" || c.StorageLocation == "4001");
Expression<Func<Inventory, bool>> expression3 = c => othersPlants.Contains(c.Plant);

if (cnPlants.Any())
{
    expression = expression1;
}
if (hfPlant)
{
    expression = Expression.Lambda<Func<Inventory, bool>>(Expression.Or(expression.Body, expression2.Body), expression.Parameters);
}
if (othersPlants.Any())
{
    expression = Expression.Lambda<Func<Inventory, bool>>(Expression.Or(expression.Body, expression3.Body), expression.Parameters);
}
query = query.Where(expression);
posted @ 2025-03-03 15:04  暖暖De幸福  阅读(12)  评论(0)    收藏  举报