表中的行是多对多的关系并没有得到适当的字段id

时间:2017-11-30 19:51:17

标签: asp.net entity-framework entity

我无法从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。

0 个答案:

没有答案