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 are using the database-first approach and recently switched from EF Core 6 to EF Core 7. So I used the reverse engineering tool with EF Core 7, which now seem to have a problem with some of our navigation properties.
Given the following simplified schema (german):
Table Mitarbeiter (employee)
Column - Mitarbeiter_Nr (int - no PK)
Table Rechnung_Kopf (invoice)
Column - Sachbearbeiternummer (int, FK to Mitarbeiter.Mitarbeiter_Nr)
Column - Vertreternummer (int, FK to Mitarbeiter.Mitarbeiter_Nr)
The RE-Tool provides the following result (simplified):
[Table("Mitarbeiter", Schema = "dbo")]
[Index("MitarbeiterNr", Name = "AK_Mitarbeiter", IsUnique = true)]
public partial class Mitarbeiter
{
[Required]
[Column("Mitarbeiter_Nr")]
public int? MitarbeiterNr { get; set; }
public virtual ICollection<RechnungKopf> RechnungKopfSachbearbeiternummerNavigation { get; } = new List<RechnungKopf>();
public virtual ICollection<RechnungKopf> RechnungKopfVertreternummerNavigation { get; } = new List<RechnungKopf>();
}
[Table("Rechnung_Kopf", Schema = "dbo")]
public partial class RechnungKopf
{
public int? Sachbearbeiternummer { get; set; }
public int? Vertreternummer { get; set; }
public virtual Mitarbeiter SachbearbeiternummerNavigation { get; set; }
public virtual Mitarbeiter VertreternummerNavigation { get; set; }
}
Now whenever we query some data of RechnungKopf, the following exception will occur:
Invalid column name "SachbearbeiternummerNavigationMitarbeiterNr".
Invalid column name "VertreternummerNavigationMitarbeiterNr".
Looking at the other (working) navigation properties there is always the [InverseProperty] and [ForeignKey] attribute, which is missing here. Adding it by hand won't fix the error though.
When we generated the code with EF Core 6, it was exactly the same, but we didn't get the errors mentioned above.
What is going wrong here and how to fix it?
Provide technical details
EF Core version in use: EF Core 7
Is Handlebars used: no
Is T4 used: no
Is .dacpac used: no
EF Core Power Tools version: 2.5.1206.0
Database engine: SQL Server
Visual Studio version: Visual Studio 2022
Error Stacktrace:
bei Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
bei Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
bei Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
bei Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
bei Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
bei Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()
bei Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
bei Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
bei Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
bei Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
bei Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
bei Microsoft.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
bei Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
bei Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.InitializeReader(Enumerator enumerator)
bei Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.<>c.b__21_0(DbContext _, Enumerator enumerator)
bei Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded)
bei Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.MoveNext()
bei System.Collections.Generic.List1..ctor(IEnumerable1 collection)
bei System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
bei FlexoSoftPlus.Database.PpgDbContext.HoleRechnungsdetails(String rechnungsnummer) in C:\Users\extern7\source\repos\FlexoSoftPlusV1\FlexoSoftPlus.Database\PartialExtents\DbContext\Rechnungswesen.cs: Zeile1606
bei FlexoSoftPlus.Modules.Rechnungsverwaltung.ViewModels.RechnungsverwaltungViewModel.d__103.MoveNext() in C:\Users\extern7\source\repos\FlexoSoftPlusV1\FlexoSoftPlus.Modules\Rechnungsverwaltung\ViewModels\RechnungsverwaltungViewModel.Logik.cs: Zeile943
The text was updated successfully, but these errors were encountered:
@ErikEJ, I'm a bit confused by the unique constraint part of the title in #29418 I'm looking at my project and when generating using EF Core 7 and Use DataAnnotation attributes to configure the model, literally every single .HasForeignKey() is gone from the context. The [ForeignKey("ColumnId")] attributes are still there on the entities themselves, as they were under EF Core 6. However under EF Core 6 both .HasForeignKey() and [ForeignKey("ColumnId")] were present. These are you basic foreign key references from a dependent tables to the primary key on the principal tables.
I'm trying to understand if there are any consequences here? Or is it OK as long as either .HasForeignKey() or [ForeignKey("ColumnId")] is present.
We are using the database-first approach and recently switched from EF Core 6 to EF Core 7. So I used the reverse engineering tool with EF Core 7, which now seem to have a problem with some of our navigation properties.
Given the following simplified schema (german):
Table Mitarbeiter (employee)
Column - Mitarbeiter_Nr (int - no PK)
Table Rechnung_Kopf (invoice)
Column - Sachbearbeiternummer (int, FK to Mitarbeiter.Mitarbeiter_Nr)
Column - Vertreternummer (int, FK to Mitarbeiter.Mitarbeiter_Nr)
The RE-Tool provides the following result (simplified):
Now whenever we query some data of RechnungKopf, the following exception will occur:
Looking at the other (working) navigation properties there is always the [InverseProperty] and [ForeignKey] attribute, which is missing here. Adding it by hand won't fix the error though.
When we generated the code with EF Core 6, it was exactly the same, but we didn't get the errors mentioned above.
What is going wrong here and how to fix it?
Provide technical details
EF Core version in use: EF Core 7
Is Handlebars used: no
Is T4 used: no
Is .dacpac used: no
EF Core Power Tools version: 2.5.1206.0
Database engine: SQL Server
Visual Studio version: Visual Studio 2022
Error Stacktrace:
The text was updated successfully, but these errors were encountered: