0

EF LINQ query datetime - LINQ to Entities doesn’t recognize the method System.DateTime ToDateTime(System.String) method

I can't get a result, what is wrong with DateTime in where clause? I would like to find for example at 26.07.2016. I get the error, see the title. Here the code: var query = from c in db.Name where DbFunctions.TruncateTime(c.Createdat) == DbFunctions.TruncateTime(Convert.ToDateTime(txtFilter.Text.Trim()).Date) select new { c.Id, c.Createdat, c.OrderNr }; gvName.Datasource = query.OrderBy(c => c.OrderNr).ToList(); In database for Createdat is in it like: 2016-07-26 19:38:19.017 Thank you

2nd Feb 2022, 8:08 PM
codie
codie - avatar
1 Odpowiedź
+ 1
Ef can't recognize Convert.toDateTime inside the linq, so use local variable and then use ef
2nd Feb 2022, 8:36 PM
hossein B
hossein B - avatar