中间层建立上下文录制对象及录制属性。如下范例:
1 public bool CancelChangeEvent(ClientContext context, Dbs dbs, int encounterId, int transferId, int sickbedId, ref DataManagerContext dataContext) 2 { 3 DataManager manager; 4 IList<IEntityWithKey> recordedlist; 5 6 recordedlist = new List<IEntityWithKey>() { dtos, dtoEncounter }; 7 manager = DataManagerFactory.Create(recordedlist); 8 manager.RecordProperty<DtoTransfer>(a => a.IsTransferedOverTo); 9 manager.RecordProperty<DtoMonitorEvent>(a => a.RecorderId, a => a.EventDateTime, a => a.EndOn, a => a.Description, a => a.IxsEventII, a => a.RowVersion); 10 manager.RecordProperty<DtoEncounter>(a => a.StatusCodeId, a => a.SickBedOrganizationId, a => a.ResponsibleDepartmentId, a => a.IsTransferred, a => a.BabyFlag, a => a.SeqNoText, a => a.MotherEncounterId, a => a.RowVersion); 11 ... ... 12 13 manager.UpdateContext(dataContext); 14 return true; 15 }
仓储对应的方法需要将返回的上下文应用到实体对应的DTO上(上下文已根据DTO主键建立属性键值对),范例代码如下:
1 public bool CancelChangeEvent(ITransfer entity, int newsickbedId) 2 { 3 DataManagerContext dataContext = new DataManagerContext(); 4 5 using (ServiceProxy<ITransferSvc> obj = GetObject<ITransferSvc>()) 6 { 7 DtoTransfer dto = DtoAccessor.GetFrom<DtoTransfer>(entity).GetDto(); 8 DtoEncounter dtoEncounter = DtoAccessor.GetFrom<DtoEncounter>(entity.Owner).GetDto(); 9 10 ret = obj.Service.CancelChangeEvent(Context, DbsKind.GetDbs(), entity.Owner.Id, entity.Id, newsickbedId, ref dataContext); 11 if (ret) 12 { 13 DataManager dataManager = DataManagerFactory.Create(dtoEncounter); 14 dataManager.ApplyContext(dataContext); 15 DtoAccessor.GetFrom<DtoEncounter>(entity.Owner).SetDto(dtoEncounter); 16 17 dataManager = DataManagerFactory.Create(dto); 18 dataManager.ApplyContext(dataContext); 19 } 20 } 21 return true; 22 }