-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Alternate key in TPT Table is dropped in the same migration it was created. #22942
Comments
If I understand correctly you want to have different names for the primary key columns in different tables mapped to the hierarchy. #19811 will enable this. |
Thank you. That kind of works - the important thing is that we are using the same named Column name as we had, but the column in the inheriting table does not update the property with the value, can we get it to do that as well? For instance I have a User relation which i want to inherit Contact. But I want a named property of UserId to be used instead of ContactId (yes I can specify the "UserId" as the column name for the shadow property called "ContactId"), but can I get the TPT feature to simply use the property 'UserId' instead of the shadow property ? This is the normal way we do TPT in our monolith and there are many of these examples. Some do use the convention of using the base table's primary key name on both sides of the relation, but many do not. And I wish that the TPT feature did not delete the inheriting table's PrimaryKey and replace it with an AlternateKey why? It also replaces an AlternateKey on the base table. The following code gets ignored/deleted in the migration. modelBuilder.Entity<Contact>(entity =>
{
entity.ToTable("Contact");
entity.HasAlternateKey(e => new { e.ContactName, e.ContactId })
.HasName("iContact-ContactName");
} |
Is this code not in included in EF Core version: 5.0.0-rc.1.20451.13 ? |
#19811 should enable this too.
Alternate keys aren't supported on derived types yet, see #2611. There might be a bug as EF should throw an exception for this instead for creating a different key, I'll investigate.
No, #19811 is not implemented yet. |
In the "20201010045907_2 handle inheritence'" migration I can see migrationBuilder.AddUniqueConstraint(
name: "iContact-ContactName",
table: "Contact",
columns: new[] { "ContactName", "ContactID" }); Why do you say that it's ignored? |
@AndriySvyryd
Is there a way i can get a version of EF5 with the changes for #19811 ? |
I see,
No, that feature hasn't been implemented yet. |
@AndriySvyryd |
@RonOsmo Yes, that's the current plan. |
It's dropped in the |
File a bug
I am trying to get EFCore 5 RC to populate a portion of our database, the application is a legacy monolithic web app.
The trouble is I am trying to add base classes with TPT. Of course I have used the ToTable() function to separate the tables.
For example there are several hierarchies:
EFCore does not honor these primary keys on the Employee or User classes but always seems to drop the original primary key and to add an alternate key named ContactID. I have tried hard to find a way around the problem but to no avail !
The latest migration looks wrong to me.
Include your code
Phase1.zip
Include provider and version information
EF Core version: 5.0.0-rc.1.20451.13
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 3.1.0
Operating system: Windows [Version 10.0.19041.508]
IDE: Visual Studio 2019 16.7.5
The text was updated successfully, but these errors were encountered: