'Entity Framework Core creating a duplicate foreign key

I am using .NET Core 6 with Entity Framework Core 6. I have seen many questions on StackOverflow regarding this issue but they are outdated. lots of methods are changed in Entity Framework Core 6.

Here is my model class:

    [Key]
    public Guid FileId { get; set; }
    public string Name { get; set; }

    [ForeignKey("UserId")]
    public Guid UserId { get; set; }
    public virtual SUser SUser { get; set; }
    [ForeignKey("KeyId")]
    public Guid KeyId { get; set; }
    public virtual SKey SKey { get; set; }

In my DB context I am modeling a database on creating:

modelBuilder.Entity<SFile>()
            .HasOne(x => x.SKey)
            .WithMany()
            .OnDelete(DeleteBehavior.NoAction);

When I see the tables keys in SQL I saw it created SKeyId two times with names SKeySkeyId and SkeySkeyId1.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source