LINQ to Entities does not recognize the method 'Int32 ToInt32 Converting String to Int

前端 未结 2 1724
栀梦
栀梦 2020-12-12 04:38

I have a LINQ statement that i want to do a sum of some a single column that is of type String.

I am trying to do the following statement where i am Converting.ToInt

相关标签:
2条回答
  • 2020-12-12 05:06

    You can't translate ToInt32 to T-SQL. One way to make it work is to run it in memory based on the list retrieved from the database like this

    var CoreData = coresdb.Productions
        .Where(item => item.Date >= StartShift && item.Date <= EndDate)
        .ToList()  // get the data into memory first.
        .Sum(x => Convert.ToInt32(x.ShootCount));
    

    Updated: Moved the ToList() after the where clause.

    0 讨论(0)
  • 2020-12-12 05:10

    If you dont want to materialize the query (retrieve the data) you can use cast (i.e. (int) x.ShootCount). Is converted to SQL CAST AS statement.

    0 讨论(0)
提交回复
热议问题