Linq更新语句

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; //设置要更新的属性


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值