问题
.NET 5 preview 8 is just released and I've been testing the brand new TPT feature. I've installed the .NET 5 preview 8 Runtime and SDK.
I created a .NET Core class library, installed the dotnet-ef
preview 8 NuGet, updated the dotnet-ef
tool with the following command (administrator):
dotnet tool update --global dotnet-ef --version 5.0.0-preview.8.20407.4
I've build the following database model:
public class MintPlayerContext : DbContext
{
// dotnet ef migrations add AddInitialEntities
// dotnet ef --version
public MintPlayerContext()
{
}
public DbSet<Subject> Subjects { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Artist> Artists { get; set; }
public DbSet<Song> Songs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=MintPlayerTPT;Trusted_Connection=True;ConnectRetryCount=0");
}
}
[Table("Subjects")]
public class Subject
{
public int Id { get; set; }
public string Memo { get; set; }
}
[Table("People")]
public class Person : Subject
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
[Table("Artists")]
public class Artist : Subject
{
public string Name { get; set; }
public int YearStarted { get; set; }
public int YearQuit { get; set; }
}
[Table("Songs")]
public class Song : Subject
{
public string Title { get; set; }
public DateTime Released { get; set; }
}
and created/executed the database migrations:
dotnet ef migrations add AddInitialEntities
dotnet ef database update
Somehow this results in the following tables:
The glue between the tables seems to be missing. And even more odd is the TPT explanation at https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-ef-core-5-0-preview-8/#table-per-type-tpt-mapping, where they state that the Pet
table gets an AnimalId
column. With TPT it's expected that the Animal
table gets some AnimalType
and AnimalTypeId
columns.
So what's up with this? Is this a misconception or is Microsoft (due to performance considerations) still sticking to some spin-off database structure?
来源:https://stackoverflow.com/questions/63624654/entity-framework-core-tpt