ef 多表添加(關聯)
阿新 • • 發佈:2017-07-13
[] tin product cnblogs 增加 pro save 關聯 添加
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 多表添加(關聯)