Closed miehler closed 1 year ago
I think this is a bug. Using the same configuration from a project running on VS2019 .NET Core 5 and got the same bug as well
I can't reproduce this using the current version. Using the Sandbox_EFCore test project, and adding a foreign key to a relationship, I see the following generated:
modelBuilder.Entity<global::Sandbox_EF6.Master>()
.HasMany<global::Sandbox_EF6.Detail>(p => p.Details)
.WithOne()
.HasForeignKey(k => k.Fkey)
.IsRequired();
Did you set the model property Allow Modeled Foreign Keys
to true in the designer properties? Click on the designer background, and it'll be the first property in the Code Generation
group.
Hi Michael,
Did you set the model property
Allow Modeled Foreign Keys
to true in the designer properties?
Yes, I did. I have attached my example project for you, resulting in the differing pieces of generated code mentioned above.
Kind regards, Axel
Hi there, I have the same problem but only with bidirectional associations. Unidirectional associations work as designed. So I think it's a bug. Kind regards, Scooter
Hi @msawczyn,
do you have any update on this issue?
Best regards, Axel
Using the latest version in the Marketplace (4.2.0) and the supplied sample project, I get
modelBuilder.Entity<global::EFVisualEditorTest.Child>()
.ToTable("Child")
.HasKey(t => t.ID);
modelBuilder.Entity<global::EFVisualEditorTest.Child>()
.Property(t => t.ID)
.ValueGeneratedOnAdd()
.IsRequired();
modelBuilder.Entity<global::EFVisualEditorTest.Child>()
.Property(t => t.PID)
.IsRequired();
modelBuilder.Entity<global::EFVisualEditorTest.Child>().HasIndex(t => t.PID);
modelBuilder.Entity<global::EFVisualEditorTest.Parent>()
.ToTable("Parent")
.HasKey(t => t.ID);
modelBuilder.Entity<global::EFVisualEditorTest.Parent>()
.Property(t => t.ID)
.ValueGeneratedOnAdd()
.IsRequired();
modelBuilder.Entity<global::EFVisualEditorTest.Parent>()
.HasMany<global::EFVisualEditorTest.Child>(p => p.Children)
.WithOne(p => p.Parent)
.HasForeignKey(k => k.PID)
.IsRequired();
Possibly something slipped past my QA in the version you're reporting on, but it looks all good now.
Thanks for following up.
Hi there,
somehow Setting custom foreign key names in EF Visual Editor for VS 2022 no longer works for me. It did work in VS 2019 though.
Here's the relevant code generated by v3.0.7.2 in VS 2019:
And this is the code generated by v4.1.2.0 in VS 2022:
HasForeignKey
is missing, hence EF Core tries to select a non-existingParentID
column.Am I doing something wrong or is this a bug?
Kind regards, Axel