Ignoring Dictionary properties are not working
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
I have two classes:
public class Student : EntityBase
{
public Guid Id { get; set; }
public string Name { get; set; }
public int Score { get; set; }
}
public abstract class EntityBase
{
public Dictionary<string, object> Test { get; set; }
public Dictionary<string, object> Test2 { get; set; }
}
My configuartion:
static IEdmModel GetEdmModel()
{
var odataBuilder = new ODataConventionModelBuilder();
odataBuilder.EntitySet<Student>("Student");
var entity = odataBuilder.EntityType<Student>();
entity.DerivesFrom<EntityBase>();
entity.Ignore(s => s.Test);
entity.Ignore(s => s.Test2);
var baseEntity = odataBuilder.EntityType<EntityBase>();
baseEntity.Abstract();
baseEntity.Ignore(s => s.Test);
baseEntity.Ignore(s => s.Test2);
return odataBuilder.GetEdmModel();
}
I am getting error on https://localhost:44383/odata/Student
System.ArgumentException: Found more than one dynamic property container in type 'Student'. Each open type must have at most one dynamic property container. (Parameter 'propertyInfo')
at Microsoft.OData.ModelBuilder.StructuralTypeConfiguration.AddDynamicPropertyDictionary(PropertyInfo propertyInfo)
at Microsoft.OData.ModelBuilder.ODataConventionModelBuilder.MapStructuralType(StructuralTypeConfiguration structuralType)
at Microsoft.OData.ModelBuilder.ODataConventionModelBuilder.MapTypes()
at Microsoft.OData.ModelBuilder.ODataConventionModelBuilder.GetEdmModel()
at Microsoft.AspNetCore.OData.Extensions.ActionDescriptorExtensions.GetEdmModel(ActionDescriptor actionDescriptor, HttpRequest request, Type entityClrType)
at Microsoft.AspNetCore.OData.Query.ODataQueryParameterBindingAttribute.ODataQueryParameterBinding.BindModelAsync(ModelBindingContext bindingContext)
at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder.BindModelAsync(ModelBindingContext bindingContext)
at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.OData.Batch.ODataBatchMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
There should not be this error because I ignored dictionaries
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.
Research direction
Start at StructuralTypeConfiguration.AddDynamicPropertyDictionary and follow ODataConventionModelBuilder.MapStructuralType and MapTypes while reproducing the Student model and GetEdmModel call. Done means the supplied ignored Test and Test2 dictionaries no longer produce the multiple dynamic property container exception when requesting /odata/Student.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100