我正在学习c#和angular2。我构建了一个web.api并希望扩展/操作json(以减少api调用)。
在我的web.api中,我得到了第一个产品:
return _context.ProductData
.Where(c => productgrouplist.Contains(c.groupid) && c.date > DateTime.Now)
.Include(c => c.group)
.GroupBy(p => p.groupid)
.Select(g => g.OrderBy(p => p.date).First());

目前主json是这样的:
[
{
"productid": 183438053218929,
"date": "2016-12-06T21:45:00",
"groupid": 1,
"title": "Testproduct1",
"description": "Test1",
"category": null,
"level_sub": "",
"level_top": "test1",
"group": {
"groupid": 1,
"groupname": "Cat1",
"grouplong": "Testcat1 long",
"grouplastupdate": "2016-11-30T00:00:00"
}
},
{
"productid": 183438053218940,
"date": "2016-12-06T20:45:00",
"groupid": 2,
"title": "Testproduct2",
"description": "Test2",
"category": null,
"level_sub": "",
"level_top": "test2",
"group": {
"groupid": 2,
"groupname": "Cat2",
"grouplong": "Testcat2 long",
"grouplastupdate": "2016-11-30T00:00:00"
}
}
]

并通过新的web.api调用获取以下内容(每组1个)。这就是为什么我想要同一组的下一个产品应该是第一个产品中的追随者。这可能在(核心)web.api中吗? Groupinfo不需要跟随者。完美将是这样的json结果:
[
{
"productid": 183438053218929,
"date": "2016-12-06T21:45:00",
"groupid": 1,
"title": "Testproduct1",
"description": "Test1",
"category": null,
"level_sub": "",
"level_top": "test1",
"group": {
"groupid": 1,
"groupname": "Cat1",
"grouplong": "Testcat1 long",
"grouplastupdate": "2016-11-30T00:00:00"
}
"follower": {
"productid": 183438053218930,
"date": "2016-12-06T22:45:00",
"groupid": 1,
"title": "Testproduct1bfollow",
"description": "Test1b",
"category": null,
"level_sub": "test2sub",
"level_top": "test2",
"group": {
"groupid": 1,
"groupname": "Cat1",
"grouplong": "Testcat1 long",
"grouplastupdate": "2016-11-30T00:00:00"
}
}
},
{
"productid": 183438053218940,
"date": "2016-12-06T20:45:00",
"groupid": 2,
"title": "Testproduct2",
"description": "Test2",
"category": null,
"level_sub": "",
"level_top": "test2",
"group": {
"groupid": 2,
"groupname": "Cat2",
"grouplong": "Testcat2 long",
"grouplastupdate": "2016-11-30T00:00:00"
}
"follower": {
"productid": 183438053218941,
"date": "2016-12-06T21:00:00",
"groupid": 2,
"title": "Testproduct2bfollow",
"description": "Test2b",
"category": null,
"level_sub": "test3sub",
"level_top": "test3",
"group": {
"groupid": 2,
"groupname": "Cat2",
"grouplong": "Testcat2 long",
"grouplastupdate": "2016-11-30T00:00:00"
}
}
}
]

这可能吗?
非常感谢。不幸的是,我仍然完全过度训练,因为我是一个c#beginner :(