Error Linq to Entities Datetime

后端 未结 4 698
时光说笑
时光说笑 2021-01-25 00:37

I have the following code

var dates = query.Select(
                 x => DateTime.ParseExact(x.Date, \"yyyy-MM\", CultureInfo.InvariantCulture));

var minDat         


        
4条回答
  •  不思量自难忘°
    2021-01-25 01:07

    Well, the error is actually quite clear. There is no translation in Linq to Entities of ParseExact to SQL.

    Remember, Entity Framework, under the covers, converts the query to a SQL command or set of commands. If EF doesn't know how to translate something, it throws this error.

    One possible solution, while not terribly efficient, is to convert the IQueryable to IEnumerable, which will allow you to execute the statement.

    var dates = query.ToList().Select(
                 x => DateTime.ParseExact(x.Date, "yyyy-MM", CultureInfo.InvariantCulture));
    

提交回复
热议问题