c# - Linq GroupBy and Sum for MVVM from stored procedure -


i have looked on other posts cant find need context. program works when don't try , add in groupby sum using linq. pulling data stored procedure using mvvm. model

public class relationshipexperience {     [key, column(order = 1)]     public double earned { get; set; }      [key, column(order = 2)]     public double incloss { get; set; }      [key, column(order = 3)]     public double expenses { get; set; }      [key, column(order = 4)]     public double balance { get; set; }      [key, column(order = 5)]     public string uwyear { get; set; }      public int programid { get; set; }      public int inprogramchain { get; set; } } 

my current, working method

public ilist<relationshipexperience> sp_getrelationshipexperience(int programid) {     return _catcontext.sp_getrelationshipexperience(programid).tolist(); } 

i want sum of columns using (earned, incloss,expenses,balance) , groupby uwyear. here attempt

    public ilist<relationshipexperience> sp_getrelationshipexperience(int programid)     {         return _catcontext.sp_getrelationshipexperience(programid)         .groupby(l => l.uwyear)         .select(r => new relationshipexperience         {             uwyear = r.key,             earned = r.sum(c => c.earned),             incloss = r.sum(c => c.incloss),             expenses = r.sum(c => c.expenses),             balance = r.sum(c => c.balance)          }).tolist();     } 

what doing wrong? in advance

    public ilist<relationshipexperience> sp_getrelationshipexperience(int programid, bool allprograms)     {             var output = _catcontext.sp_getrelationshipexperience(programid) .where(l => l.inprogramchain == 1) .groupby(l => l.uwyear) .select(r => new relationshipexperience {     uwyear = r.key,     earned = r.sum(c => c.earned),     incloss = r.sum(c => c.incloss),     expenses = r.sum(c => c.expenses),     balance = r.sum(c => c.balance),  }).tolist();              return output;          } 

this works, shows results in datagrid


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -