我正在尝试将 linq 中的 Venue/Showtime 关系序列化为 Javascript,并且很难弄清楚对它们进行分组,基本上我有来自 linq 的以下输出
Venue ID | Venue Name | Party Name | Party ID
74 CityStars Cinema Late Night (3am) 2
74 CityStars Cinema Sunrise (6am) 3
74 CityStars Cinema Morning (9am) 4
74 CityStars Cinema Noon (12pm) 5
74 CityStars Cinema After Noon (3pm) 6
现在我的查询是这样的:
JavaScriptSerializer rSerialize = new JavaScriptSerializer();
var enVenues = from v in db.Venues
join t in db.VenueTimes on v.ID equals t.VenueID
join p in db.VenueParty on t.PartyID equals p.ID
select new
{
VenueID = v.ID,
VenueName = v.TitleEn,
PartyName = p.NameEn,
PartyID = p.ID
};
rMovie.VenuesArray = rSerialize.Serialize(enVenues);
但我想做的是按地点名称将 linq 分组为如下所示:
{[
"VenueID" : 74,
"VenueName" : "CitySars Cinema",
"VenueShowtimes" : [ {"Late Night", 2}, {"Sunrise" , 3}, etc... ]
]}
我怎样才能做到这一点?