asp.net mvc - Creating the chart from database data .The entity or complex type cannot be constructed in a LINQ to Entities query -


i'm working on mvc application want display graph show how many loads per company have on database.

the entity or complex type 'emis.models.report' cannot constructed in linq entities query error message

the generator in report model companyname in loads model.

this action method in controller

public actionresult getloadspiechart()     {         iqueryable<report> data = cust in db.loads                                   group cust cust.companyname provgroup                                   select new report()                                   {                                        generator = provgroup.key,                                        countload = provgroup.count(),                                        percentage = ((provgroup.count() * 100) / (db.loads.count()))                                   };           arraylist xvalue = new arraylist();         arraylist yvalue = new arraylist();          var results = data;          results.tolist().foreach(rs => xvalue.add(rs.generator));         results.tolist().foreach(rs => yvalue.add(rs.countload));          var key = new chart(width: 600, height: 400, theme: charttheme.blue);         key.addseries(charttype: "column", xvalue: xvalue, yvalues: yvalue);         key.addtitle("loads statistics per generator");         key.write("png");         return null;      } 

report model

public class report {      public int id { get; set; }      public string generator { get; set; }      public int countload { get; set; }      public int percentage { get; set; } } 

load model

public class load {     [key]     [databasegenerated(databasegeneratedoption.identity)]     public int loadnumber { get; set; }      [required]     [display(name = "generator")]     public string companyname { get; set; }      [required]     [display(name = "truck")]     public string numberplate { get; set; }      [required]     [display(name = "vehicle size/ capacity")]     public string vehiclesize { get; set; }      [required]     [display(name = "ph")]     public int ph { get; set; }      [required]     [display(name = "amount")]     public decimal amount { get; set; }       [display(name = "penalty amount")]     public decimal penaltyamount { get; set; }      [required]     [display(name = "load date")]     [displayformat(dataformatstring = "{0:dd-mm-yyyy}")]     [datatype(datatype.date)]     public datetime loaddate { get; set; }      public virtual icollection<generator> generator { get; set; } } 

i have tried follow solutions of same error couldn't help. please help!!!!

var data = (from cust in db.loads                                   group cust cust.companyname provgroup                                   select new                                    {                                        generator = provgroup.key,                                        countload = provgroup.count(),                                        percentage = ((provgroup.count() * 100) / (db.loads.count()))                                   }).tolist();           arraylist xvalue = new arraylist();         arraylist yvalue = new arraylist();            data.foreach(rs => xvalue.add(rs.generator));         data.foreach(rs => yvalue.add(rs.countload));          var key = new chart(width: 600, height: 400, theme: charttheme.blue);         key.addseries(charttype: "column", xvalue: xvalue, yvalues: yvalue);         key.addtitle("loads statistics per generator");         key.write("png");         return null; 

first typing in mobile might have tweak bit. first doing here writing projection query custom object report

as query queryable executing when tolist. in code never using report model directly.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -