If user defines property like:
public object[] Property1 { get; set; }
or
public IEnumerable<object> Property2 { get; set; }
public ICollection<object> Property3 { get; set; }
The model builder will add System.Object as entity type.
Since every clr type derives from System.Object, model builder will report error if any entity type defining a key.
The exception is:
System.InvalidOperationException occurred
HResult=-2146233079
Message=Cannot define keys on type 'QueryableRepro.Models.AnotherModel' deriving from 'System.Object'. Only the root type in the entity inheritance hierarchy can contain keys.
Source=System.Web.Http.OData
StackTrace:
at System.Web.Http.OData.Builder.EntityTypeConfiguration.DerivesFrom(IEntityTypeConfiguration baseType) in C:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\runtime\src\System.Web.Http.OData\OData\Builder\EntityTypeConfiguration.cs:line 158
InnerException:
> System.Web.Http.OData.dll!System.Web.Http.OData.Builder.EntityTypeConfiguration.DerivesFrom(System.Web.Http.OData.Builder.IEntityTypeConfiguration baseType) Line 161 C#
System.Web.Http.OData.dll!System.Web.Http.OData.Builder.ODataConventionModelBuilder.DiscoverInheritanceRelationships() Line 209 + 0xc bytes C#
System.Web.Http.OData.dll!System.Web.Http.OData.Builder.ODataConventionModelBuilder.GetEdmModel() Line 166 + 0x8 bytes C#
System.Web.Http.OData.dll!System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel.AnonymousMethod__0(object _) Line 32 + 0xb bytes C#
mscorlib.dll!System.Collections.Concurrent.ConcurrentDictionary<object,object>.GetOrAdd(object key, System.Func<object,object> valueFactory) + 0x49 bytes
System.Web.Http.OData.dll!System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel(System.Web.Http.Controllers.HttpActionDescriptor actionDescriptor, System.Type entityClrType) Line 27 + 0x67 bytes C#
System.Web.Http.OData.dll!System.Web.Http.QueryableAttribute.CreateQueryContext(System.Type entityClrType, System.Web.Http.HttpConfiguration configuration, System.Web.Http.Controllers.HttpActionDescriptor actionDescriptor) Line 209 + 0xb bytes C#
System.Web.Http.OData.dll!System.Web.Http.QueryableAttribute.OnActionExecuted(System.Web.Http.Filters.HttpActionExecutedContext actionExecutedContext) Line 147 + 0xe bytes C#
public object[] Property1 { get; set; }
or
public IEnumerable<object> Property2 { get; set; }
public ICollection<object> Property3 { get; set; }
The model builder will add System.Object as entity type.
Since every clr type derives from System.Object, model builder will report error if any entity type defining a key.
The exception is:
System.InvalidOperationException occurred
HResult=-2146233079
Message=Cannot define keys on type 'QueryableRepro.Models.AnotherModel' deriving from 'System.Object'. Only the root type in the entity inheritance hierarchy can contain keys.
Source=System.Web.Http.OData
StackTrace:
at System.Web.Http.OData.Builder.EntityTypeConfiguration.DerivesFrom(IEntityTypeConfiguration baseType) in C:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\runtime\src\System.Web.Http.OData\OData\Builder\EntityTypeConfiguration.cs:line 158
InnerException:
> System.Web.Http.OData.dll!System.Web.Http.OData.Builder.EntityTypeConfiguration.DerivesFrom(System.Web.Http.OData.Builder.IEntityTypeConfiguration baseType) Line 161 C#
System.Web.Http.OData.dll!System.Web.Http.OData.Builder.ODataConventionModelBuilder.DiscoverInheritanceRelationships() Line 209 + 0xc bytes C#
System.Web.Http.OData.dll!System.Web.Http.OData.Builder.ODataConventionModelBuilder.GetEdmModel() Line 166 + 0x8 bytes C#
System.Web.Http.OData.dll!System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel.AnonymousMethod__0(object _) Line 32 + 0xb bytes C#
mscorlib.dll!System.Collections.Concurrent.ConcurrentDictionary<object,object>.GetOrAdd(object key, System.Func<object,object> valueFactory) + 0x49 bytes
System.Web.Http.OData.dll!System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel(System.Web.Http.Controllers.HttpActionDescriptor actionDescriptor, System.Type entityClrType) Line 27 + 0x67 bytes C#
System.Web.Http.OData.dll!System.Web.Http.QueryableAttribute.CreateQueryContext(System.Type entityClrType, System.Web.Http.HttpConfiguration configuration, System.Web.Http.Controllers.HttpActionDescriptor actionDescriptor) Line 209 + 0xb bytes C#
System.Web.Http.OData.dll!System.Web.Http.QueryableAttribute.OnActionExecuted(System.Web.Http.Filters.HttpActionExecutedContext actionExecutedContext) Line 147 + 0xe bytes C#