给出以下字符串arrray:
string[] ranges = new string[]{"0-100", "100-200", "500-1000"};
Run Code Online (Sandbox Code Playgroud)
我想在linq表达式中动态表达这一点 - 有点像:
var query = from p in Db.Products()
where p.Amount() >= 0
where p.Amount() <= 100
where p.Amount() >= 101
where p.Amount() <= 200
where p.Amount() >= 500
where p.Amount() <= 1000
select p;
Run Code Online (Sandbox Code Playgroud)
我知道如何从数组中提取值,这不是问题,但更多的是如何在for循环中动态构建linq表达式:
string[] ranges = new string[]{"0-100", "100-200", "500-1000"};
foreach (var item in ranges)
{
int min = int.Parse(item.Split('-').First());
int max = int.Parse(item.Split('-').Last());
//Linq expression?
}
Run Code Online (Sandbox Code Playgroud)