LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression

后端 未结 11 2276
花落未央
花落未央 2020-11-22 10:41

I\'m migrating some stuff from one mysql server to a sql server but i can\'t figure out how to make this code work:

using (var context = new Context())
{
            


        
11条回答
  •  面向向阳花
    2020-11-22 11:22

    Cast table to Enumerable, then you call LINQ methods with using ToString() method inside:

        var example = contex.table_name.AsEnumerable()
    .Select(x => new {Date = x.date.ToString("M/d/yyyy")...)
    

    But be careful, when you calling AsEnumerable or ToList methods because you will request all data from all entity before this method. In my case above I read all table_name rows by one request.

提交回复
热议问题