EF6 更新实体对象


1、整体更新

2、自动部分更新

 

3、指定字段手动更新

        public bool Update(long waybillId,long so_header_id, long shipment_order_id, string package_no,NumberStatusType statusType)
        {
            bool isOk = false;
            using (B2C.DAL.DbWaybillContext context = new DAL.DbWaybillContext(ExpressWaybill.GetWriteConnectionString()))
            {
                this.TurnOnConsoleLog(context);
                B2C.Model.Waybill.ExpressWaybillNumberDTO entity = new Model.Waybill.ExpressWaybillNumberDTO();
                entity.Id = waybillId;
                entity.so_header_id = so_header_id;
                entity.ShipOrderId = shipment_order_id;
                entity.PackageNO = package_no;
                entity.NumberStatus = statusType;

                var entityEntry = context.Entry<B2C.Model.Waybill.ExpressWaybillNumberDTO>(entity);
                entityEntry.State = System.Data.Entity.EntityState.Unchanged;
                entityEntry.Property("so_header_id").IsModified = true;
                entityEntry.Property("ShipOrderId").IsModified = true;
                entityEntry.Property("PackageNO").IsModified = true;
                entityEntry.Property("NumberStatus").IsModified = true;
                context.Configuration.ValidateOnSaveEnabled = false;
                int rowsAffected = context.SaveChanges();
                if (rowsAffected > 0)
                    isOk = true;
                context.Configuration.ValidateOnSaveEnabled = true;
            }
            return isOk;
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM