I have problem with saving many to many relationship. When I run the code, my mapping table "dbo.UserTown" does not have any data saved in this any idea why?
I have wrote my function for saving the users with lists of towns
public void Save(User user)
{
context.User.Add(user);
context.SaveChanges();
}
My classes are like this:
public class User
{
public long UserId { get; set; }
public String Nickname { get; set; }
[InverseProperty("Residents")]
public virtual ICollection<Town> Residencies { get; set; }
}
and
public class Town
{
public long TownId { get; set; }
public String Name { get; set; }
public virtual ICollection<User> Residents { get; set; }
}