c# - Linq let not available in groupby -


this query:

// stores of types interested in. var desiredtypes = new[]     {         dbstoerungglobalmanager.enumstoerart.kommunikation,         dbstoerungglobalmanager.enumstoerart.kaelte     };  list<faultstatisticmodel> data2 = (from in data                                    let statistictype = (dbstoerungglobalmanager.enumstoerart)a.fart // cast , store statistic type                                    desiredtypes.contains(statistictype) // filter collection of desired types                                    group a.fdatum.tostring(groupby) mg                                    join b in dtlist on mg.key equals b.tostring(groupby)                                    select new faultstatisticmodel                                    {                                        date = mg.key,                                         // make sure correct property receives result                                        kommunikationvalue = statistictype == dbstoerungglobalmanager.enumstoerart.kommunikation ? mg.count() : 0,                                        kaeltevalue = statistictype == dbstoerungglobalmanager.enumstoerart.kaelte ? mg.count() : 0                                    }).tolist(); 

sadly doesnt work, statistic type isnt available in select new, think has todo groupby before

a group typically contains multiple, that's why can't access statistictype anymore. group can contain multiple different types since you're not grouping it

in fact want group it..

you can use anonymous type group 2 properties:

var data2 = in data             let statistictype = (dbstoerungglobalmanager.enumstoerart)a.fart             desiredtypes.contains(statistictype) // filter collection of desired types             group new { datum = entityfunctions.truncatetime(a.fdatum), type = statistictype } mg             join b in dtlist on mg.key.datum equals entityfunctions.truncatetime(b)             select new faultstatisticmodel             {                 date = mg.key.datum,                 kommunikationvalue = mg.key.type == dbstoerungglobalmanager.enumstoerart.kommunikation ? mg.count() : 0,                 kaeltevalue = mg.key.type == dbstoerungglobalmanager.enumstoerart.kaelte ? mg.count() : 0             };  list<faultstatisticmodel> data2list = data2.tolist();  

but maybe want count records of specific statistic-type, use approach:

var data2 = in data             let statistictype = (dbstoerungglobalmanager.enumstoerart)a.fart             desiredtypes.contains(statistictype) // filter collection of desired types             group entityfunctions.truncatetime(a.fdatum) mg             join b in dtlist on mg.key equals entityfunctions.truncatetime(b)             select new faultstatisticmodel             {                 date = mg.key,                 kommunikationvalue = mg.count(x => (dbstoerungglobalmanager.enumstoerart)x.fart == dbstoerungglobalmanager.enumstoerart.kommunikation),                 kaeltevalue = mg.count(x => (dbstoerungglobalmanager.enumstoerart)x.fart == dbstoerungglobalmanager.enumstoerart.kaelte)             }; 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -