Improve exception message for TPC + Owned Entities Configuration
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
I've been attempting to use the TPC strategy where a owned entity is configured on the base entity, but I cannot get the migrations to generate the owned entity properties on the derived entities.
I've instead needed to move the `OwnsOne` configuration to each derived entity (`FileSystemDirectory`, `FileSystemFile`) to get the migration to include the `PathInfo` properties. If I do that however, I cannot filter or sort on the base entity as the LINQ expression cannot be translated.
It's something I've been banging my head against a wall at for some time now, as being able to sort and filter on the base class is important, but it cannot be done inside the generated SQL statement as the following fails.
```C#
await database
.Entries
.OrderBy(x => x.PathInfo.Name)
.ToListAsync();
```
I'd ideally want to setup the entities and configuration like below, but it doesn't seem to be supported when the `OwnsOne` is configured on the base class.
```C#
public abstract class FileSystemEntry
{
public int Id { get; set; }
public PathInfo PathInfo { get; set; }
public FileSystemDirectory? ParentDirectory { get; set; }
}
public class FileSystemDirectory : FileSystemEntry
{
}
public class FileSystemFile : FileSystemEntry
{
public long Size { get; set; }
}
public class PathInfo
{
public string Name { get; init; }
public string FullName { get; init; }
public string Extension { get; init; }
public string DirectoryPath { get; init; }
}
public class FileSystemEntryConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder
.UseTpcMappingStrategy();
builder
.OwnsOne(p => p.PathInfo);
}
}
```
Does this issue relate to https://github.com/dotnet/efcore/issues/9630? Or is something missing or being configured incorrectly here?
Contributor guide
Assessment
This issue has not been assessed yet.