1.
AMS_Plan_Item planitem = new AMS_Plan_Item();
planitem.plan_item_id = dtl.planitemid;
AMS_Plan_Item planchange= entity.AMS_Plan_Item.AsNoTracking().Where(p => p.plan_item_id == planitem.plan_item_id).FirstOrDefault();
//AsNoTracking() 设置不追踪,相当于一个新的。和第二种方法可以进行同等操作
planitem.supply_amount = planchange.supply_amount+ dtl.quantity;
entity.AMS_Plan_Item.Attach(planitem);
DbEntityEntry<AMS_Plan_Item> entry = entity.Entry<AMS_Plan_Item>(planitem);
entry.State = System.Data.Entity.EntityState.Unchanged;
entry.Property(p => p.supply_amount).IsModified = true; //设置要更新的属性
int i = entity.SaveChanges();
2.
AMS_Plan_Item itemplan = new AMS_Plan_Item();
itemplan.plan_item_id = stritme[i];
context.AMS_Plan_Item.Attach(itemplan);
itemplan.audit_status = 9;
itemplan.back_date = DateTime.Now;
itemplan.backname = SessionHelper.GetSessionUser().UserId;
itemplan.reason = detail;
3.
List<AMS_Plan_Item> lstlstlst = context.AMS_Plan_Item.Where(p => p.audit_status == 4 && strstrstr.Contains(p.asset_id) && ((p.plan_type == 0 && p.plan_id == next) || (p.plan_type == 1 && p.plan_id == cur))).ToList();
foreach (var item in lstlstlst)
{
item.audit_status = 9;
item.back_date = DateTime.Now;
item.backname = SessionHelper.GetSessionUser().UserId;
item.reason = detail;
context.AMS_Plan_Item.Attach(item);
context.Entry(item).State = System.Data.Entity.EntityState.Modified;
}
4.
AMS_asset_categories item = new AMS_asset_categories();
item.category_id = dto.category_id;
//entity.Set<AMS_asset_categories>().Attach(item);
entity.AMS_asset_categories.Attach(item);
item.SortCode = dto.SortCode;
item.name = dto.name;
item.description = dto.description;
item.available = dto.available;
item.parent_warehouse_id = dto.parent_warehouse_id;
item.modify_date = DateTime.Now;
item.modify_user = SessionHelper.GetSessionUser().UserId;
//entity.AMS_asset_categories.Attach(item);
//DbEntityEntry<AMS_asset_categories> entry = entity.Entry<AMS_asset_categories>(item);
//entry.State = System.Data.Entity.EntityState.Unchanged;
//entry.Property(p => p.modify_date).IsModified = true; //设置要更新的属性
//entry.Property(p => p.modify_user).IsModified = true; //设置要更新的属性
//entry.Property(p => p.name).IsModified = true; //设置要更新的属性
//entry.Property(p => p.description).IsModified = true; //设置要更新的属性
//entry.Property(p => p.available).IsModified = true; //设置要更新的属性
//entry.Property(p => p.parent_warehouse_id).IsModified = true; //设置要更新的属性