`EntityTypeConfiguration<TEntityType>.HasKey` does not allow a nested expression
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
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:
modelBuilder.EntityType<Dto>()
.HasKey(a => a.General.Id);
Data Model
For the purposes of this issue, consider a reduced version:
public class Dto
{
public DtoGeneral General { get; set; }
}
public class DtoGeneral
{
public int Id { get; set; }
}
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.
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 the EntityTypeConfiguration.HasKey entry point and trace how the provided member expression is validated. Use the nested Dto and DtoGeneral example to determine whether nested keys are supported, then verify the behavior against the issue's OData configuration scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100