本文介绍了LINQ到实体无法识别方法“的System.DateTime ToDateTime(System.String)”方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想一个应用程序转换的EntityFramework codefirst。 我现在的代码是 字符串sFrom =26/12/2013; SELECT * FROM横贯其中,CONVERT(日期时间,日期,105)GT = CONVERT(日期时间,'+ sFrom +',105) 和我试图 的DateTime dtFrom = Convert.ToDateTime(sFrom); TransRepository.Entities.Where(X => Convert.ToDateTime(x.Date)> = dtFrom) 但我得到这样 错误Please helpThanks in advance 解决方案 when you do this:TransRepository.Entities.Where(x =>Convert.ToDateTime(x.Date) >= dtFrom)LINQ to Entities cannot translate most .NET Date methods (including the casting you used) into SQL since there is no equivalent SQL.What you need to do is to do below: DateTime dtFrom = Convert.ToDateTime(sFrom ); TransRepository .Entities.ToList()//forces execution .Where(x =>Convert.ToDateTime(x.Date) >= dtFrom)but wait the above query will fetch entire data, and perform .Where on it, definitely you don't want that,simple soultion would be this,personally, I would have made my Entity field as DateTime and db column as DateTimebut since, your db/Entity Date field is string, you don't have any other option, other than to change your field in the entity and db to DateTime and then do the comparison 这篇关于LINQ到实体无法识别方法“的System.DateTime ToDateTime(System.String)”方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 00:28