Given the following string arrray:
string[] ranges = new string[]{"0-100", "100-200", "500-1000"};
I would like to dynamically express this in a linq expression - Something along the lines of:
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;
I know how to extract the values from the array so that's not the issue, but more so how do i dynamically build the linq expression in a for loop:
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?
}