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
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.
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.