Package update to Microsoft.AspNetCore.OData 8.0.4 not allowing to have multiple EDM for different controllers
@xuzhg is already working on this.
Since Jan 4, 2022.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Earlier in OData v7, we have route mapped with multiple edm for different controller in startup using the method "MapODataServiceRoute" and ODataRoute attribute decorator is added in controller.
like this :-
appBuilder.UseEndpoints(odata =>
{
odata.MapControllers();
// Enable the dependency injection support for all HTTP routes
odata.EnableDependencyInjection();
// Add querying options(Select, Expand, Filter, OrderBy, MaxTop)
odata.Select().Expand().Filter().OrderBy().MaxTop(null).Count();
odata.MapODataServiceRoute("Accounts", "api/Accounts",
configureAction => configureAction.
AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEdmModel),
serviceProvider => edmModelAccounts()))
odata.MapODataServiceRoute("Devices", "api/Devices",
configureAction => configureAction.
AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEdmModel),
serviceProvider => edmModelDevices()))
}
AccountsController : ODataController
[HttpGet]
[ODataRoute("", RouteName = "Accounts")]
[EnableQuery]
public async Task<IActionResult> GetAccounts()
{
return Ok(_db.Accounts);
}
DevicesController : ODataController
[HttpGet]
[ODataRoute("", RouteName = "Devices")]
[EnableQuery]
public async Task<IActionResult> GetDevices()
{
return Ok(_db.Devices);
}
Endpoint URLS:
http://localhost:52434/api/Accounts
Response:
{
"@odata.context": "http://localhost:52434/api/Accounts/$metadata",
"value": [
{}
]
}
http://localhost:52434/api/Devices
Response:
{
"@odata.context": "http://localhost:52434/api/Devices/$metadata",
"value": [
{}
]
}
But after updating to OData ASP.NET Core OData 8.0.4, facing difficulty in mapping multiple EDM to different controller without changing the route URL because ODataRoute attribute is not exists.
Added the code below in startup:
services.AddControllers().AddOData(option => option.Select().Filter().Count().OrderBy().Expand().SetMaxTop(null)
.AddRouteComponents("api/Accounts", ODataHelper.edmModelAccounts(),
builder => builder.AddSingleton<IODataSerializerProvider, ODataSerializerProvider>())
.AddRouteComponents("api/Devices", ODataHelper.edmModelDevices(),
builder => builder.AddSingleton<IODataSerializerProvider, ODataSerializerProvider>())
and removed the odatroute attribute from controller action methods. but the endpoints mentioned above returns as not implemented.
and it returns data when endoints are given as below:
http://localhost:52434/api/Accounts/**Accounts**
http://localhost:52434/api/Devices/**Devices**
it expects additional entity set to be added in route path.
Accounts and Devices entity sets are different from each other and not related to each other, so we need to map these different EDM's to different controllers.
Is there anyway to make it work without changing the endpoint URL? Please help
Framework : .Net 6
Microsoft.AspNetCore.OData : 8.0.4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.