You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run an initial migration, everything works without issue, and the many-to-many table relationship you auto-generated below appears in the migration. However, if I try to use an IEntityTypeAddedConvention to make things snake case, the migration aborts.
Unable to create a 'DbContext' of type 'SdcDatabaseContext'. The exception 'Cannot use table 'dictionary2' for entity type 'ExportControlClassificationNumberSoftwarePackage (Dictionary<string, object>)' since it is being used for entity type 'DistributionFileSoftwarePackage (Dictionary<string, object>)' and potentially other entity types, but there is no linking relationship. Add a foreign key to 'ExportControlClassificationNumberSoftwarePackage (Dictionary<string, object>)' on the primary key properties and pointing to the primary key on another entity type mapped to 'dictionary2'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Good code you generate if I don't add the convention
migrationBuilder.CreateTable(name:"ExportControlClassificationNumberSoftwarePackage",columns: table =>new{ExportControlClassificationNumbersId=table.Column<int>(type:"integer",nullable:false),SoftwarePackagesId=table.Column<int>(type:"integer",nullable:false)},constraints: table =>{table.PrimaryKey("PK_ExportControlClassificationNumberSoftwarePackage", x =>new{x.ExportControlClassificationNumbersId,x.SoftwarePackagesId});table.ForeignKey(name:"FK_ExportControlClassificationNumberSoftwarePackage_ExportCont~",column: x =>x.ExportControlClassificationNumbersId,principalTable:"ExportControlClassificationNumber",principalColumn:"Id",onDelete:ReferentialAction.Cascade);table.ForeignKey(name:"FK_ExportControlClassificationNumberSoftwarePackage_SoftwarePa~",column: x =>x.SoftwarePackagesId,principalTable:"SoftwarePackage",principalColumn:"Id",onDelete:ReferentialAction.Cascade);});
Include provider and version information
EF Core version: 9.0.0
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL 9.0.1
Target framework: .NET 9
Operating system: Windows 11
IDE: Visual Studio 2022 17.12.3
The text was updated successfully, but these errors were encountered:
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
I tracked this down. In my posted convention code, where I call SetTableName is the issue. It appears that for the many-to-many tables that EF will automatically generate for me, the name is always passed to me as Dictionary`2. So I have to change that bit of code to this:
if(nameis not "Dictionary`2")entityType.SetTableName(ToSnakeCase(name));
While that solves my issue, I'm wondering if there's a better way to handle this, as that feels fragile as I'm depending on some internal convention you're using that could change.
Ask a question
When I run an initial migration, everything works without issue, and the many-to-many table relationship you auto-generated below appears in the migration. However, if I try to use an
IEntityTypeAddedConvention
to make things snake case, the migration aborts.Include your code
Failure message from migration
Good code you generate if I don't add the convention
Include provider and version information
EF Core version: 9.0.0
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL 9.0.1
Target framework: .NET 9
Operating system: Windows 11
IDE: Visual Studio 2022 17.12.3
The text was updated successfully, but these errors were encountered: