c# - Error Linq to Entities Datetime -
i have following code
var dates = query.select( x => datetime.parseexact(x.date, "yyyy-mm", cultureinfo.invariantculture)); var mindate = dates.min(x => x);
but when execute that, exception
system.data.entity.dll not handled in user code
additional information: linq entities not recognize method 'system.datetime parseexact(system.string, system.string, system.iformatprovider)' method, , method cannot translated store expression.
what doing wrong? , how can fix that?
well, error quite clear. there no translation in linq entities of parseexact sql.
remember, entity framework, under covers, converts query sql command or set of commands. if ef doesn't know how translate something, throws error.
one possible solution, while not terribly efficient, convert iqueryable ienumerable, allow execute statement.
var dates = query.tolist().select( x => datetime.parseexact(x.date, "yyyy-mm", cultureinfo.invariantculture));
Comments
Post a Comment