Search code examples
c#asp.net-core.net-core.net-6.0odata-v4

OData enum mapping as int not working in 8.2.3


In .Net Core 2.2 project we used Odata 7.1.0 version. We mapped Enum in model separately with NotMapped property then in model builder we mapped it with StructuralTypeConfiguration it is working fine It is returning ReportStatusId as int and ReportStatus as string value.

Model
--------------------------------------------------------------------------
[Newtonsoft.Json.JsonProperty("ReportStatus", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public EnumReportStatus ReportStatus { get; set; } = EnumReportStatus.Draft;
        [NotMapped]
        [Newtonsoft.Json.JsonProperty("ReportStatusId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public int ReportStatusId
        {
            get
            {
                return (int)ReportStatus;
            }
        }

Model Builder 
----------------------------------------------------------------------
StructuralTypeConfiguration<ReportingItem> rpItem = builder.EntitySet<ReportingItem>(nameof(ReportingItem)).EntityType.Count().Select().Filter().OrderBy().Expand();
            rpItem.Property(g => g.ReportStatusId);

Now we are migrating to .NET6 we have upgraded Odata to 8.2.3. Now above code is not working. Are we missing anything here ??


Solution

  • Finally found the solution with some and error. You just need to do one change in EDM model binding.
    Remove Count().Select().Filter().OrderBy().Expand() from EDM binding. It worked for me.