Я пытаюсь создать службу OData в ASP Core для потребления в Excel и столкнулся с проблемой при попытке использовать ее. Это странно, поскольку другие подобные таблицы, кажется, потребляются нормально.
Вот ответ (полученный с помощью PostMan):
{
"@odata.context": "https://localhost:44349/odata/$metadata#ScenarioYearValues",
"value": [
{
"ScenarioYearValueId": 46
},
{
"ScenarioYearValueId": 47
},
{
"ScenarioYearValueId": 48
},
{
"ScenarioYearValueId": 49
},
{
"ScenarioYearValueId": 50
},
{
"ScenarioYearValueId": 51
},
{
"ScenarioYearValueId": 52
},
{
"ScenarioYearValueId": 161
},
{
"ScenarioYearValueId": 162
},
{
"ScenarioYearValueId": 178
}
]
}
А вот метаданные:
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="Backend.ImpPlanner.Models" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="ScenarioYearValue">
<Key>
<PropertyRef Name="ScenarioYearValueId" />
</Key>
<Property Name="ScenarioYearValueId" Type="Edm.Int32" Nullable="false" />
</EntityType>
</Schema>
<Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityContainer Name="Container">
<EntitySet Name="ScenarioYearValues" EntityType="Backend.ImpPlanner.Models.ScenarioYearValue" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Пропуская это через локальный валидатор OData (https://archive.codeplex.com/?p=odatavalidator), он сообщает мне, что это действительный OData, но Excel возвращает:
Подробности: «Нам не удалось разрешить введите имя 'ScenarioYearValues' для EdmType "
Может кто-нибудь определить, где я ошибаюсь?
ОБНОВЛЕНИЕ:
Вот пример другого контроллера, который работает:
{
"@odata.context": "https://localhost:44349/odata/$metadata#ScenarioRows",
"value": [
{
"ScenarioRowId": 317,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 29,
"SchoolId": 22,
"DepartmentId": 2692,
"FundId": null,
"Description": "Budget setting 20/21 ",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": null
},
{
"ScenarioRowId": 318,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 18,
"SchoolId": 22,
"DepartmentId": 361,
"FundId": null,
"Description": "B/fwd from PSB 2",
"Enabled": false,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": ""
},
{
"ScenarioRowId": 319,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 28,
"SchoolId": 22,
"DepartmentId": 369,
"FundId": null,
"Description": " Jan 32 Oct 25 (7 year 6 leavers)",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": null
},
{
"ScenarioRowId": 320,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 30,
"SchoolId": 22,
"DepartmentId": 373,
"FundId": null,
"Description": "B/fwd from PSB 4",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": ""
},
{
"ScenarioRowId": 321,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 20,
"SchoolId": 22,
"DepartmentId": 2819,
"FundId": null,
"Description": "Budget setting 20/21 ",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": null
},
{
"ScenarioRowId": 322,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 43,
"SchoolId": 22,
"DepartmentId": 374,
"FundId": null,
"Description": "Lettings income 20/21 budget",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": null
},
{
"ScenarioRowId": 323,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 61,
"SchoolId": 22,
"DepartmentId": 375,
"FundId": null,
"Description": "B/fwd from PSB 7",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": null
},
{
"ScenarioRowId": 324,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 36,
"SchoolId": 22,
"DepartmentId": 368,
"FundId": null,
"Description": "B/fwd from PSB 8",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": null
},
{
"ScenarioRowId": 325,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 269,
"SchoolId": 22,
"DepartmentId": 712,
"FundId": null,
"Description": "B/fwd from PSB 9",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": ""
},
{
"ScenarioRowId": 326,
"ScenarioId": null,
"ContractId": null,
"FinanceCodeId": 29,
"SchoolId": 28,
"DepartmentId": 2692,
"FundId": null,
"Description": "B/fwd from PSB 10",
"Enabled": true,
"CalculatorId": 37,
"MonthProfileId": 17,
"CashFlowProfileId": null,
"MatEditOnly": false,
"Notes": ""
}
]
}
и метаданные:
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="Backend.ImpPlanner.Models" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="ScenarioRow">
<Key>
<PropertyRef Name="ScenarioRowId" />
</Key>
<Property Name="ScenarioRowId" Type="Edm.Int32" Nullable="false" />
<Property Name="ScenarioId" Type="Edm.Int32" />
<Property Name="ContractId" Type="Edm.Int32" />
<Property Name="FinanceCodeId" Type="Edm.Int32" Nullable="false" />
<Property Name="SchoolId" Type="Edm.Int32" Nullable="false" />
<Property Name="DepartmentId" Type="Edm.Int32" Nullable="false" />
<Property Name="FundId" Type="Edm.Int32" />
<Property Name="Description" Type="Edm.String" Nullable="false" />
<Property Name="Enabled" Type="Edm.Boolean" Nullable="false" />
<Property Name="CalculatorId" Type="Edm.Int32" />
<Property Name="MonthProfileId" Type="Edm.Int32" Nullable="false" />
<Property Name="CashFlowProfileId" Type="Edm.Int32" />
<Property Name="MatEditOnly" Type="Edm.Boolean" Nullable="false" />
<Property Name="Notes" Type="Edm.String" MaxLength="5000" />
</EntityType>
</Schema>
<Schema Namespace="Backend.ImpPlanner.ViewModels" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="ScenarioRowDetailModel" BaseType="Backend.ImpPlanner.Models.ScenarioRow">
<Property Name="Editable" Type="Edm.Boolean" Nullable="false" />
</EntityType>
</Schema>
<Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityContainer Name="Container">
<EntitySet Name="ScenarioRows" EntityType="Backend.ImpPlanner.Models.ScenarioRow" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>