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
We recently upgraded from EF Core 6 to EF Core 8, and we realised that we are missing an IndexerProperty in scaffolded DBContext for many to many relation.
The j.IndexerProperty("EffectiveFrom").HasColumnType("date"); is not automatically generated which is causing failures, so it needs to be added manually.
Unit test error message:
System.InvalidOperationException : The relationship from 'AnnualValueAcademicYearMapping (Dictionary<string, object>)' to 'AnnualValue' with foreign key properties {'LearnAimRef' : string, 'EffectiveFrom' : int} cannot target the primary key {'LearnAimRef' : string, 'EffectiveFrom' : DateOnly} because it is not compatible. Configure a principal key or a set of foreign key properties with compatible types for this relationship.
We couldn't find anything in the documentation, but there was a similar issue in EF Core 7 that has been resolved #32936 . Can you please advise? Thanks in advance.
Your code
[dbo].[AnnualValue]([LearnAimRef]VARCHAR(8)NOTNULL,[EffectiveFrom]DATENOT NULL,CONSTRAINT[PK_dbo_AnnualValue]PRIMARY KEY CLUSTERED ([LearnAimRef]ASC,[EffectiveFrom]ASC) WITH (FILLFACTOR =90))[dbo].[AcademicYear_Lookup]([AcademicYear][varchar](4) NOT NULL,[AcademicYearDesc][varchar](150) NULL,[AcademicYearDesc2][varchar](100) NULL,CONSTRAINT[PK_dbo_AcademicYear_Lookup]PRIMARY KEY ([AcademicYear]))[dbo].[AnnualValue_AcademicYear_Mapping]([AcademicYear]VARCHAR(4)NOTNULL,[LearnAimRef]VARCHAR(8) NOT NULL,[EffectiveFrom]DATENOT NULL,CONSTRAINT[PK_dbo_AnnualValueAcademicYearMapping]PRIMARY KEY CLUSTERED ([AcademicYear]ASC,[LearnAimRef]ASC,[EffectiveFrom]ASC) WITH (FILLFACTOR =90),CONSTRAINT[FK_dbo_AnnualValueAcademicYearMapping_AnnualValue]FOREIGN KEY ([LearnAimRef],[EffectiveFrom])REFERENCES[dbo].[AnnualValue]([LearnAimRef],[EffectiveFrom])ONDELETE CASCADE,CONSTRAINT[FK_dbo_AnnualValueAcademicYearMapping_AcademicYear_Lookup]FOREIGN KEY ([AcademicYear])REFERENCES[dbo].[AcademicYear_Lookup]([AcademicYear])ONDELETE CASCADE
);
Stack traces
Verbose output
EF Core version
8.0.12
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.Net 8.0
Operating system
Windows 11
IDE
Visual Studio 2022 17.12.3
The text was updated successfully, but these errors were encountered:
Of course, I have created a small project similar to the actual implementation so you should be able to find everything you need there. EntityFrameworkIssue.zip
Bug description
We recently upgraded from EF Core 6 to EF Core 8, and we realised that we are missing an IndexerProperty in scaffolded DBContext for many to many relation.
DB Context code snippet:
The j.IndexerProperty("EffectiveFrom").HasColumnType("date"); is not automatically generated which is causing failures, so it needs to be added manually.
Unit test error message:
System.InvalidOperationException : The relationship from 'AnnualValueAcademicYearMapping (Dictionary<string, object>)' to 'AnnualValue' with foreign key properties {'LearnAimRef' : string, 'EffectiveFrom' : int} cannot target the primary key {'LearnAimRef' : string, 'EffectiveFrom' : DateOnly} because it is not compatible. Configure a principal key or a set of foreign key properties with compatible types for this relationship.
We couldn't find anything in the documentation, but there was a similar issue in EF Core 7 that has been resolved #32936 . Can you please advise? Thanks in advance.
Your code
Stack traces
Verbose output
EF Core version
8.0.12
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.Net 8.0
Operating system
Windows 11
IDE
Visual Studio 2022 17.12.3
The text was updated successfully, but these errors were encountered: