public class marketviewmodel { public marketviewmodel() { } public string item { get; set; } public list<subitem> stationname { get; set; } } public class subitem { public string item { get; set; } } var active = actives in activestations group actives.stationname new { actives.market,actives.stationgroupint } g select new marketviewmodel { item = g.key.market, stationname = g.tolist() };
in above linq code, question how project marketviewmodel
, see stationname list of subitem.
stationname = g.tolist()
( how re-write piece ?) creates list of subitem objects
edit
activestations entity contains
- stationname(string),
- stationgroupint (int),
- market (string)
market stationname stationgroupint ---------------------------------- b 1 c 1 d 1
you can use select
on group g
create sub item.
var active = actives in activestations group actives.stationname new { actives.market,actives.stationgroupint } g select new marketviewmodel { item = g.key.market, stationname = g.select(stationname => new subitem { item = stationname }).tolist() };
Comments
Post a Comment