Building an EdmModel with inheritance relationship between entities
@gathogojr is already working on this.
Since Apr 4, 2023.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I can't seem to find the right way to build my Edm model with the following requirement :
- a base class and some derived ones, adding new specific properties
public class EntityA
{
public Guid Id { get; set; }
public string PropertyA { get; set; }
}
public class EntityB: EntityA
{
public string PropertyB { get; set; }
}
- a controller for the whole inheritance chain, calling the default route would return a collection of
EntityAs, the/Broute a collection ofEntityBs, and so on
[Route("[controller]")]
public class ControllerA : ODataController
{
[HttpGet]
[EnableQuery(PageSize = 12)]
[ProducesResponseType(typeof(IQueryable<EntityA>), 200)]
public Task<IActionResult> GetAllA()
{
IQueryable<EntityA> allA = someService.GetAllA();
return allA;
}
[HttpGet("B")]
[EnableQuery(PageSize = 12)]
[ProducesResponseType(typeof(IQueryable<EntityB>), 200)]
public Task<IActionResult> GetAllB()
{
IQueryable<EntityB> allB = someService.GetAllB();
return allB;
}
}
When I declare my Edm model using the ODataConventionModelBuilder, I cannot find a way to declare the GetAllB method as a Function on the EntitySet<EntityA> which returns a collection of EntityB.
Either I tell it it ReturnsCollection<EntityB>(), and then when the convention builder map the types hierarchy internally, it cannot register EntityB as an EntityType because it is already registered as a ComplexType, or I try to make a call to ReturnsCollectionFromEntitySet<>() but then I have to register a new EntitySet with a different name (which I think I understood will not match anymore with my odata/A/B route ?) or to bind it to the EntitySet<EntityA> and then OData sends me back the wrong type in the response's odata.context property (which I need to be exact to perform some client-side operations for displaying the data).
What did I miss ?
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.