I'm using Entity Framework Code First approach. I have these to classes. Of course, they have other fields but, they are not connected with the issue.
public class User
{
public int Id { get; set; }
public Role Role { get; set; }
public int HouseholdId { get; set; }
public virtual Household Household { get; set; }
}
public class Household
{
private ICollection<User> users;
public Household()
{
users = new HashSet<User>();
}
public int Id { get; set; }
public DateTime DateCreated { get; set; }
public virtual ICollection<User> Users
{
get { return users; }
set { users = value; }
}
}
I have the following settings applied in my OnModelCreating method:
modelBuilder.Entity<User>()
.HasRequired(u => u.Household)
.WithMany()
.WillCascadeOnDelete(false);
When I run the application, everything is correct except of the fact that the generated User table has one more foreign key added to its design:
User Table:
Id
Role
HouseholdId
**Household_Id**
Why is this happening?