In my C# MVC 5 application, I am trying to use a linq query to convert a column in my sql server table that is an NVarChar to a decimal and display it in the view.
I know that if I was to do a simple SQL query or was using webforms I could simply do the following:
Select Sum(Cast(GrandTotal as decimal)) as GrandTotal From [myDB].[dbo].[Table]
WHERE Year = '2017'
public ActionResult Total()
var model = (from p in db.Table
I'm unaware of a LINQ-To-Entities function that can do this. Id do it using LINQ-To-Objects:
var result = (from p in db.Table where "2017" == p.Year select p).ToList(); var model = (from p in result select decimal.Parse(p.GranTotal)).Sum();