Basically I have a QueryExtender control of ASP.NET and First I need to Convert sql varchar value to TimeSpan of CSharp type then apply Linq OrderBy Clause on it, but get an error when execute.
Here is my code:
protected void FilterProducts(object sender, CustomExpressionEventArgs e)
{
e.Query = (from p in e.Query.Cast<accounts>()
select p).OrderBy(p=> TimeSpan.Parse(p.TimeTo));
}
ERROR: LINQ to Entities does not recognize the method 'System.TimeSpan Parse(System.String)' method, and this method cannot be translated into a store expression.
Without knowing all about the shape of your
p.TimeTodata I think you can use the string value to order by, this way:This way, a value
1:00will be sorted before11:00.EDIT
Take:
And see the difference between
and
Which is:
and