using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntityType<Derived1>();
builder.EntityType<Derived2>();
var model = builder.GetEdmModel();
var entityType1 = model.FindType("Default.Derived1") as EdmEntityType;
var idProperty1 = entityType1!.FindProperty("id");
var annotation1 = model.GetAnnotationValue<ClrPropertyInfoAnnotation>(idProperty1);
var entityType2 = model.FindType("Default.Derived2") as EdmEntityType;
var idProperty2 = entityType2!.FindProperty("id");
var annotation2 = model.GetAnnotationValue<ClrPropertyInfoAnnotation>(idProperty2);
if (annotation1 is null || annotation2 is null)
{
throw new InvalidOperationException();
}
public abstract class BaseEntity
{
public Guid Id { get; set; }
}
public sealed class Derived1 : BaseEntity { }
public sealed class Derived2 : BaseEntity { }
Expected result
Annotations for basetype properties should be added to both derived types.
Actual result
Annotations for basetype properties are only added to the last type added.
Additional detail
Stepping through the code shows that EdmTypeMap.EdmProperties has only 1 PropertyInfo item while in .Net 6 there are 2.
In .Net 7 annotations for basetype properties are only added to the last type.
Assemblies affected
Microsoft.OData.ModelBuilder 1.0.9
Reproduce steps
This program throws
InvalidOperationException
, while it runs fine when TargetFramework isnet6.0
.ConsoleApp.csproj
Program.cs
Expected result
Annotations for basetype properties should be added to both derived types.
Actual result
Annotations for basetype properties are only added to the last type added.
Additional detail
Stepping through the code shows that
EdmTypeMap.EdmProperties
has only 1PropertyInfo
item while in .Net 6 there are 2.I have found 2 workarounds, either:
builder.EntityType<BaseEntity>();