C# 我无法使odata查询计数嵌套元素
我试图计算odata查询中的相关对象,但我没有得到汇总结果,只有详细信息 如果我计算第一个工作正常的对象类型C# 我无法使odata查询计数嵌套元素,c#,.net,odata,asp.net-core-webapi,core,C#,.net,Odata,Asp.net Core Webapi,Core,我试图计算odata查询中的相关对象,但我没有得到汇总结果,只有详细信息 如果我计算第一个工作正常的对象类型 .../ObjectType1?$apply=groupby((ObjectType1Type),aggregate(Id with countdistinct as total)) .../ObjectType2?$apply=groupby((ObjectType2Type),aggregate(Id with countdistinct as total)) 我得到了预期的结果
.../ObjectType1?$apply=groupby((ObjectType1Type),aggregate(Id with countdistinct as total))
.../ObjectType2?$apply=groupby((ObjectType2Type),aggregate(Id with countdistinct as total))
我得到了预期的结果
[
{
"ObjectType1Type": "Type1",
"total": 15
},
{
"ObjectType1Type": "Type2",
"total": 1
}
]
[
{
"ObjectType2Type": "Type1",
"total": 13
},
{
"ObjectType2Type": "Type2",
"total": 15
},
{
"ObjectType2Type": "Type3",
"total": 13
},
{
"ObjectType2Type": "Type4",
"total": 15
}
]
如果我计算第二种工作正常的对象类型
.../ObjectType1?$apply=groupby((ObjectType1Type),aggregate(Id with countdistinct as total))
.../ObjectType2?$apply=groupby((ObjectType2Type),aggregate(Id with countdistinct as total))
我得到了预期的结果
[
{
"ObjectType1Type": "Type1",
"total": 15
},
{
"ObjectType1Type": "Type2",
"total": 1
}
]
[
{
"ObjectType2Type": "Type1",
"total": 13
},
{
"ObjectType2Type": "Type2",
"total": 15
},
{
"ObjectType2Type": "Type3",
"total": 13
},
{
"ObjectType2Type": "Type4",
"total": 15
}
]
如果我要求得到一个对象并计算所有相关对象
.../ObjectType1(Id)?$expand=ObjectType2($apply=groupby((ObjectType2Type),aggregate(Id with countdistinct as total)))
我明白了,我不希望
{
"@odata.context": "https://localhost:44391/v1.0/odata/$metadata#Objects1(Objects2())/$entity",
"Id": "50e445b9-ad81-4919-b7b9-4b11b67277d5",
"ObjectType1": "Type1",
"Name": "My Object",
"Timestamp": "2018-11-14T16:26:28+0000",
"Message": "This is the message",
"ObjectType2": [
{
"Id": "6778883d-df2a-4ec6-adaf-fcd05d7f4a5f",
"ObjectType2Type": "Type1"
},
{
"Id": "19d46eb7-c0dc-478c-a522-9b0c928b29c4",
"ObjectType2Type": "Type1"
},
{
"Id": "79cffedd-2243-4725-bfd5-a592ff599fa5",
"ObjectType2Type": "Type1"
},
{
"Id": "e119dd31-8521-45c4-b4da-8fab691cdd93",
"ObjectType2Type": "Type1"
},
{
"Id": "9a188e60-30ed-4b77-a358-e75ffc829362",
"ObjectType2Type": "Type1"
},
{
"Id": "0b06e260-87ef-42b9-87c4-bf8e63395a36",
"ObjectType2Type": "Type1"
},
{
"Id": "d5a6ef17-710c-4761-b5d0-7f609ac07f1a",
"ObjectType2Type": "Type1"
},
{
"Id": "3133d38d-84a3-4502-b661-3a8ecdc4a5c9",
"ObjectType2Type": "Type1"
},
{
"Id": "89760715-86fd-4e8d-98e6-b755854ce1e7",
"ObjectType2Type": "Type1"
}
]
}
我期待着以下。。。
(根据)
应该这样做吗?
我错过了什么?
相关NUGET的版本是
- “Microsoft.AspNetCore.Mvc.Versioning”Version=“3.0.0”
- “Microsoft.AspNetCore.OData”Version=“7.1.0”
- “Microsoft.AspNetCore.OData.Versioning”Version=“3.0.0”
- “Microsoft.OData.Core”Version=“7.6.0”