首页 > 代码库 > ef 多表添加(关联)

ef 多表添加(关联)

static void Main(string[] args)
{
      //创建上下文对象 PpDbEntities dbEntities = new PpDbEntities(); #region Add() //多表增加 // Customer customer = new Customer(); customer.Name = "mmm"; dbEntities.Customer.Add(customer); //customer.ID = 5; //dbEntities.Entry(customer).State=EntityState.Deleted; //dbEntities.Entry<ProductInfo>(productInfo).State = EntityState.Deleted; // OrderInfo orderInfo = new OrderInfo(); orderInfo.Name = "mmm订单2"; dbEntities.OrderInfo.Add(orderInfo);
//第二张增加 用客户指向订单 customer.OrderInfo.Add(orderInfo); dbEntities.SaveChanges();
}

 

ef 多表添加(关联)