1

I have the following classes:

public partial class User
{
    [Key]
    public int UserId { get; set; }
    public string Username { get; set; }
    [ScriptIgnore]
    public virtual ICollection<Subscription> Followers { get; set; }
    [ScriptIgnore]
    public virtual ICollection<Subscription> Following { get; set; }
}

public partial class Subscription
{
    [Key]
    public int SubscriptionId { get; set; }
    public virtual User Follower { get; set; }
    public virtual User Followed { get; set; }
    public int status { get; set; }
}

The users table is generated fine but the Subscriptions table goes like this:

Subscriptions( SubscriptionId, status, Follower_UserId, Followed_UserId, 
User_UserId, User_UserId1 )

These two last columns are not necesary and they are getting in fact NULL values

sports
  • 7,851
  • 14
  • 72
  • 129

1 Answers1

3

Try to use this:

public partial class Subscription
{
    [Key]
    public int SubscriptionId { get; set; }
    [InverseProperty("Followers")]
    public virtual User Follower { get; set; }
    [InverseProperty("Following")]
    public virtual User Followed { get; set; }
    public int status { get; set; }
}
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • I also having similar issue, explained here https://stackoverflow.com/questions/58408156/enitity-framework-each-property-name-in-a-type-must-be-unique . Not sure why its adds extra column. Tried with [InverseProperty("ResponseId")] on property ResponseId. Did not work for me – Developer Oct 16 '19 at 12:25