Error Linq to Entities Datetime

后端 未结 4 767
时光说笑
时光说笑 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:01

    LINQ to Entities takes your LINQ query and converts it to SQL code that it then executes against the database. That means that the code you write has to be able to be converted to SQL code. There is no way to convert DateTime.ParseExact to SQL code, hence the exception. You will need to evaluate a LINQ to Entities query by calling ToArray and then you can perform a second LINQ to Objects query on that and it will understand DateTime.ParseExact.

提交回复
热议问题