c# - How to flatten nested dictionaries within Class using LINQ -


the closest solution looking thread how flatten nested objects linq expression

but error trying approach

the type arguments method 'system.linq.enumerable.selectmany(system.collections.generic.ienumerable, system.func>)' cannot inferred usage. try specifying type arguments explicitly.

my code:

var aa = t.data.selectmany(x =>                      x.value.innerdata.selectmany(y => new { /*error @ selectmany*/                     url = x.key,                     disp = x.value.disp,                     date = y.key,                     count = y.value.count,                     rank = y.value.rank,        })); 

my classes:

public class tdata {     public dictionary<string, tdetail> data { get; set; } }  public class tdetail {     public string disp { get; set; }      [newtonsoft.json.jsonproperty("data")]     public dictionary<string, metrics> innerdata { get; set; }  }  public class metrics {     public string count { get; set; }     public string rank { get; set; } } 

the json 3rd party api looks below:

{   "data": {     "abc.com": {       "disp": "#712176",       "data": {         "2015-02-08": {           "count": 4,           "rank": 5.8         },         "2015-02-23": {           "count": 3,           "rank": 8.3         },         "2015-03-14": {           "count": 5,           "rank": 3.7         }       }     },     "nbc.com": {       "disp": "#822176",       "data": {         "2015-02-08": {           "count": 3,           "rank": 5.5         },         "2015-02-23": {           "count": 5,           "rank": 8.4         },         "2015-03-14": {           "count": 7,           "rank": 4.7         }       }     }   } } 

how specify type arguments explicitly in case? thanks.

too many selectmany:

var t = new tdata(); // tdata  var aa = t.data.selectmany(x =>         x.value.innerdata.select(y => new         {             url = x.key,             disp = x.value.disp,             date = y.key,             count = y.value.count,             rank = y.value.rank,         })); 

the inner 1 must select.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -