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

前端 未结 4 501
再見小時候
再見小時候 2020-12-15 13:36

I am trying to convert one application to EntityFrameWork codefirst. My present code is

 string sFrom  =\"26/12/2013\";
 select * FROM Trans where  CONVERT(d         


        
4条回答
  •  我在风中等你
    2020-12-15 14:04

    Why is your date column a string? Shouldn't it be a DateTime?

    Regardless, if you attempt to perform conversions using .NET functions in a .Where statement against a repository of entities, you'll get that error.

    Your best option would be to change that column from a string to a DateTime and proceed from there. If you do, the .Where statement would be:

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

提交回复
热议问题