EdmModel with generic class
@xuzhg is already working on this.
Since Oct 5, 2021.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
I have a generic class that I want to expose in the EdmModel. The issue is the result obtained from OData, I am not showing all data.
This is the schema to be returned from the endpoint.
[
{
"item": {
"id": "string",
"resourceType": "string",
},
"etag": "string"
}
]
And this is the result when calling the endpoint. For any reason item is not showed.
{
"@odata.context": "https://localhost:44397/api/v1/Admin/$metadata#appConfig",
"value": [
{
"Etag": "Ayj8F2FzRxbqHYPrYj2Mti0pSW5lxGTZ6womMFuGWUg="
},
{
"Etag": "8KcnnNKf5g7VHP7+NHqUjlhv57Ym7F0VQpSykD9a04I="
},
{
"Etag": "LGR1OCClN6llYGTw+JZIwDOJ2zG+qXU6kLPhWRS4voU="
}
]
}
The action in the controller is defined as follow
[HttpGet("appConfig")]
[EnableQuery()]
public Task<IEnumerable<EtagItem<AppConfig>>> GetAppConfigAsync()
{
return GraphService.GetAppConfigAsync();
}
EdmModel is created like this. I tried to define an EntityType but I obtained the same result.
public static IEdmModel GetAdminEdmModel(this IServiceProvider serviceProvider)
{
var builder = new ODataConventionModelBuilder(serviceProvider);
builder.EntitySet<EtagItem<AppConfig>>("appConfig");
//builder.EntityType<AppConfig>();
//builder.EntityType<UserAppConfig>();
//builder.EntityType<GroupAppConfig>();
return builder.GetEdmModel();
}
And these are the classes, where IModelItem only exposes Id property and UserAppConfig and GroupAppConfig inherited from base class.
public sealed class EtagItem<TDocument> where TDocument : IModelItem
{
[JsonProperty(Required = Required.Always)]
public TDocument Item { get; set; }
[Key]
[JsonProperty(Required = Required.Always)]
public string Etag { get; set; }
}
public abstract class AppConfig : IModelItem
{
public string Id { get; set; }
public string ResourceType { get; set; }
}
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.