Search In
Learn from 350 other Umbracians at the annual Umbraco Conference - CodeGarden '13. More than twenty high quality sessions, open spaces, hackathons and social events you'll remember. Not to be missed! Less than 25 tickets left - get yours now!
Can somebody please point out why the following is not a valid method of checking if a number falls within a particular range?
products = products.Where(string.Format("price >= {0} and price is <= {1}", decimal.Parse(Request.Form["minPrice"]), decimal.Parse(Request.Form["maxPrice"])));
I am getting a syntax error exception which is a System.Linq.Dynamic.ParseException type if that helps.
Simon
What is the is in query? ( and price is <= {1} )
Try this :
products = products.Where(string.Format("price >= {0} && price <= {1}",decimal.Parse(Request.Form["minPrice"]),decimal.Parse(Request.Form["maxPrice"])));
What is products? you can paste the code how do you get it and how you declare it?
Hope that help.
Cheers
Thanks for pointing out my now very obvious school boy error, a case of not being able to see the wood for the trees! The issue was of course the "is" that had been added somehow in error :(
Just FYI, you can use the Where method without string.Format as it already parses the condition for parameters and replaces them, as in:
products = products.Where("price >= @0 && price <= @1", decimal.Parse(Request.Form["minPrice"]), decimal.Parse(Request.Form["maxPrice"])));
Good to know, thanks Douglas.