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(); }
时间: 2024-10-05 15:38:35