Service:
public Cart AddProductToCart(Product product, Cart cart)
{
CartProduct cartProduct = new CartProduct();
cartProduct.CartId = cart.Id;
cartProduct.ProductId = product.Id;
_dbContexet.CartProduct.Add(cartProduct);
_dbContexet.SaveChanges();
return cart;
}
I have a cart that can have many product and product that can have many carts, 1 cart belongs to 1 user...
When i try to insert this product and cart i get this error:
SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_CartProduct_Carts_ProductId". The conflict occurred in database "ManagerZ", table "dbo.Carts", column 'Id'.
The statement has been terminated
.
question from:
https://stackoverflow.com/questions/65871502/insert-statement-conflicted-with-foreign-key-ef-core-many-to-many 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…