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; }