Hello I have like this 2 tables
class User
public int UserId{get;set;}
{
....
public virtual ICollection<Product> Products{ get; set; }
...
}
class Product
{
public int ProductId{get;set}
..
public virtual User User;
...
}
I have set by Fluent Api like this
modelBuilder.Entity<User>().HasMany(x => x.Products).WithOptional();
I tried to add created product to navigation collection like this:
if (user.Products == null)
user.Products = new Collection<Product>();
user.Products.Add(product);
crud.Update(user.UserId, user);
When I am debuging I see that product has added to collection but didn’t add to database
Please help me!If need I have more information about it
1 Answer