我有 2 个实体类型买家和买家订单。买家可以包含多个买家订单,买家订单列表可以由用户编辑。当我想添加一些 BuyerOrders 时,我调用方法:
private static void CreateOrdersForBuyer(Buyer buyer, int[] selectedLeadTypes)
{
foreach (var order in selectedLeadTypes.Select(leadTypeId => new BuyerOrder
{
Buyer = buyer,
OfferTypeID = (int) OfferTypes.Referral,
Price = 1,
RegistrationDate = DateTime.Now,
StatusID = (int) BuyerOrderStatus.Pending,
LeadtypeID = leadTypeId,
Profit = 1
}))
{
buyer.BuyerOrders.Add(order);
}
}
然后保存买家:
GenericRepository.Instance.Save(buyer);
保存方法:
public virtual void Save<T>(T value) where T : class
{
//LegalLeadsDataContext.Instance = null;
LegalLeadsDataContext.Instance.GetTable<T>().Attach(value);
LegalLeadsDataContext.Instance.Refresh(RefreshMode.KeepCurrentValues, value);
LegalLeadsDataContext.Instance.SubmitChanges();
}
之后,我在数据库中看不到新的 BuyerOrders。我究竟做错了什么?