How to populate google charts using data from database created via code first - ASP.Net MVC

后端 未结 2 861
庸人自扰
庸人自扰 2020-12-21 08:33

I want to replace the hard coded data in the code below with data from my database that I\'ve created using the Code First approach.

However, I literally have no ide

2条回答
  •  死守一世寂寞
    2020-12-21 09:05

    You can try using following way

     public Product GetChartData()
        {
            Product objproduct = new Product();
    
            List yr = null;
            List sal = null;
            List pur = null;
    
            yr = db.tblCharts.Select(y => y.Years).ToList();
            sal = db.tblCharts.Select(y => y.Sale).ToList();
            pur = db.tblCharts.Select(y => y.Purchase).ToList();
            objproduct.Year = string.Join(",", yr);
            objproduct.Sale = string.Join(",", sal);
            objproduct.Purchase = string.Join(",", pur);
    
            return objproduct;
        }
    

    I hope that will resolve your problem.

提交回复
热议问题