我无法从InDirect表中获取ID到我的主表。当我用一种方法创建它时。这与许多人有很多关系。
var reservation = new Reservation()
foreach (var item in cartItems)
{
var paymentInDirect = new PaymentInDirect
{
ReservationID = reservation.ID,
Reservation = reservation,
Payment.ID= payment.ID,
};
_db.PaymentInDirect.Add(paymentInDirect );
reservation.PaymentInDirect.Add(paymentInDirect );
reservation.PaymentInDirectID = paymentInDirect .ID;
}
reservation.UserID= uzytkownikID;
reservation.DateCreatedReservation = DateTime.Now
_db.Reservation.Add(reservation);
_db.SaveChanges()
如下所示,行来自预订表,我收到了PaymentInDirectID = 0.
预留ID | PaymentInDirectID |用户名| dateCreated会
10 | 0 | 32 | 30-11-2017
如果我想从PaymentInDirectID显示一个正确的行。然后,这一行有一个适合我最近添加的预订ID。