-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EntityTypeConfiguration<TEntityType>.HasKey
does not allow a nested expression
#828
Comments
Have you thought about just creating a computed redirection I find it extremely unlikely that OData will ever support your scenario natively. But maybe I'm wrong. |
Yeah, that's quite an obvious workaround. What about my last question? |
Types that are not entities in OData are considered complex types, not owned. Usually a type is not detected as an entity if it doesn't have an ID field. There is the concept of an owned entity but that's just an entity that can only be accessed through another and doesn't have it's own entity set. These have to be configured as owned explicitly, either in the EDM, or through attributes. |
Using complex type property to define key is valid in OData spec. An example like this: <EntityType Name="Category">
<Key>
<PropertyRef Name="Info/ID" Alias="EntityInfoID" />
</Key>
<Property Name="Info" Type="Sales.EntityInfo" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
</EntityType>
<ComplexType Name="EntityInfo">
<Property Name="ID" Type="Edm.Int32" Nullable="false" />
<Property Name="Created" Type="Edm.DateTimeOffset" />
</ComplexType> But, it's not supported ODL. Once ODL supports it, I can make it work on the Web API side. See issue at: OData/odata.net#1817 |
@ElizabethOkerio was once looking into adding key and property aliasing support in ODL. |
Assemblies affected
Microsoft.AspNetCore.OData 8.0.12
Describe the bug
EntityTypeConfiguration<TEntityType>.HasKey
does not allow a nested expression.I'm trying to set up odata with DTOs, mapping to EF Core queries with Automapper.
My DTO, which I'm trying to use as the OData entity, is set up differently than the EF Core entity, it has a nested type with the general information, which has the id on it.
However, HasKey only allows member expressions, so this won't work:
Data Model
For the purposes of this issue, consider a reduced version:
Additional Notes
Are nested things even allowed btw?
EF Core has owned types, are all types that aren't entities considered owned in OData?
My model has quite a bunch of nested types, It'd be unfortunate if I had to inline all that.
The text was updated successfully, but these errors were encountered: