I'm running the Beta of OData on .Net Core. I'm trying to only enable certain features of odata depending on the controller. My startup class looks like so:
services.AddOData();
//...
app.UseMvc(routeBuilder =>
{
//routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
routeBuilder.MapODataServiceRoute("odata", null, GetModel());
routeBuilder.EnableDependencyInjection();
});
public static IEdmModel GetModel()
{
var builder = new ODataConventionModelBuilder();
var skillSet = builder.EntitySet<Skill>(nameof(Skill));
skillSet.EntityType.Count().Filter().OrderBy().Expand().Select();
builder.Namespace = "ODataTest.Models";
builder.ContainerName = "DefaultContainer";
return builder.GetEdmModel();
}
When I globally enable odata everything works fine. However, I cannot expose all of my entities
routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
but when, I try to enable odata for a specific entity set my I get an error when I attempt to filter
skillSet.EntityType.Count().Filter().OrderBy().Expand().Select();
The query specified in the URI is not valid. The property 'Name' cannot be used in the $filter query option.
For the sake of completeness here is my controller:
[HttpGet]
[EnableQuery]
public async Task<Skill[]> GetFilteredODataList(ODataQueryOptions<Skill> q)
{
var skillsQuery = this._context.Skills.AsQueryable();
if (q?.Filter != null)
{
skillsQuery = q.Filter.ApplyTo(skillsQuery, new ODataQuerySettings()) as IQueryable<Skill>;
}
return await skillsQuery.ToArrayAsync();
}