Skip to content
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

DB Scaffold Misnamed Navigation Properties #2591

Open
Pearseak opened this issue Dec 3, 2023 · 0 comments
Open

DB Scaffold Misnamed Navigation Properties #2591

Pearseak opened this issue Dec 3, 2023 · 0 comments

Comments

@Pearseak
Copy link

Pearseak commented Dec 3, 2023

dotnet 7 & 8 (AFAIK)
The Entity Framework Core database scaffold has incorrectly named the navigation properties in the Choice entity.
The properties FileUu and QuestionUu do not align with their respective foreign keys, FileUuid and QuestionUuid.

        modelBuilder.Entity<Choice>(entity =>
        {
            entity.HasKey(e => e.Uuid).HasName("choice_pk");

            entity.ToTable("choice");

            entity.Property(e => e.Uuid)
                .HasDefaultValueSql("uuid_generate_v4()")
                .HasColumnName("uuid");
            entity.Property(e => e.FileUuid).HasColumnName("file_uuid");
            entity.Property(e => e.IsCorrect)
                .HasDefaultValue(false)
                .HasColumnName("is_correct");
            entity.Property(e => e.QuestionUuid).HasColumnName("question_uuid");
            entity.Property(e => e.Text).HasColumnName("text");

            entity.HasOne(d => d.FileUu).WithMany(p => p.Choice)
                .HasForeignKey(d => d.FileUuid)
                .HasConstraintName("choice_file_uuid_fk");

            entity.HasOne(d => d.QuestionUu).WithMany(p => p.Choice)
                .HasForeignKey(d => d.QuestionUuid)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("choice_question_uuid_fk");
        });
public class Choice
{
    public Guid Uuid { get; set; }
    public Guid QuestionUuid { get; set; }
    public string? Text { get; set; }
    public Guid? FileUuid { get; set; }
    public bool? IsCorrect { get; set; }

    public virtual File? FileUu { get; set; }

    public virtual Question QuestionUu { get; set; } = null!;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant