嗨,我有2个具有一对多关系的表,我使用ado net和Join查询来获取表和被引用的表,之后我将DataTable转换为Enumerable,然后使用Linq操作将其返回为嵌套状态JSON。但是问题在于,只有GroupBy字段会使用键返回一个数据,而其他每个字段都将返回一个与记录一样多的数组
stream()
对于N:1表,我需要再次进行GroupBy,这样我就可以在细分受众群中得到这样的信息
{
"id": 23,
"date": [
"2018-01-01T00:00:00",
"2018-01-01T00:00:00",
"2018-01-01T00:00:00",
"2018-01-01T00:00:00"
],
"total_room_sold": [
41,
41,
41,
41
],
"total_rom_revenue": [
19340082,
19340082,
19340082,
19340082
],
"Segment": {
"segment_name": [
"BFR",
"DIS",
"PAR",
"LON"
],
"room_sold": [
4,
2,
1,
0
],
"revenue_by_segment": [
1904628,
686605,
461157,
0
]
}
}
我现在的代码
{
"id": 23,
"date": [
"2018-01-01T00:00:00",
"2018-01-01T00:00:00",
"2018-01-01T00:00:00",
"2018-01-01T00:00:00"
],
"total_room_sold": [
41,
41,
41,
41
],
"total_rom_revenue": [
19340082,
19340082,
19340082,
19340082
],
"Segment": [
{
"segment_name": "BFR",
"rooom_sold" : 4,
"revenue_by_segment" : 412313213
},
{
"segment_name": "BFR",
"rooom_sold" : 2,
"revenue_by_segment" : 12312313
}
]
}