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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -