LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method

c# entity-framework linq-to-entities

Question

One application is being converted to EntityFrameWork codefirst. Right now, my code is

 string sFrom  ="26/12/2013";
 select * FROM Trans where  CONVERT(datetime, Date, 105) >=   CONVERT(datetime,'" + sFrom + "',105) 

I also tried.

 DateTime dtFrom = Convert.ToDateTime(sFrom );
TransRepository.Entities.Where(x  =>Convert.ToDateTime(x.Date) >= dtFrom) 

But I encountered this problem.

LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method

kindly assist I appreciate you.

1
6
9/17/2014 11:42:02 AM

Accepted Answer

ZZZ_tmp
9
5/23/2017 12:33:00 PM

Popular Answer

Your date column is a string—why? Why is it not aDateTime ?

In any case, you'll see that problem if you try to execute conversions using.NET methods in a.Where statement against a repository of entities.

Changing that column from a string to a DateTime and continuing from there would be your best course of action. in that case, the.Where a statement like:

DateTime dtFrom = Convert.ToDateTime(sFrom );
var something = TransRepository.Entities.Where(x  => x.Date >= dtFrom) ;


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow