I want to write an ID in carID from another table, the data in it is filled in, everything is fine with it, carId = el.clothes.IdClothes
I thought the error was that the ID was not created in Order, but that was not the case
Внутреннее исключение 1:SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint “FK_OrderDetail_Clothes_clothesIdClothes”. The conflict occurred in database “ShopClothes”, table “dbo.Clothes”, column ‘IdClothes’.
`public void createOrder(Order order){order.orderTime = DateTime.Now;appDbContent.Order.Add(order);appDbContent.SaveChanges();
var items = shopCart.listShopItems;
foreach (var el in items)
{
var orderDetail = new OrderDetail()
{
carId = el.clothes.IdClothes,
orderId = order.id,
price = el.clothes.price
};
appDbContent.OrderDetail.Add(orderDetail);
}
appDbContent.SaveChanges();
}
user24902131 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.