コード例 #1
0
        public void Merge <TEntity>(TEntity entity) where TEntity : class, IDbEntity, new()
        {
            var cache = GetDbEntityManager <TEntity>().Get(entity.Id);

            if (cache == null)
            {
                throw new System.Exception(string.Format("EF缓存中找不到 {0} id:{1}", typeof(TEntity).Name, entity.Id));
            }
            PropertyUpdateHelper.UpDate <TEntity>(cache, entity);
        }
コード例 #2
0
 private void Update(HistoryEvent historyEvent)
 {
     if (historyEvent is HistoricProcessInstanceEventEntity)
     {
         HistoricProcessInstanceEventEntity data = historyEvent as HistoricProcessInstanceEventEntity;
         //TODO 不在EF上下文,再次更新会异常
         log.LogDebug("Entity当前状态", Context.CommandContext.GetEntityStateInEF <HistoricProcessInstanceEventEntity>(data).ToString());
         if (Context.CommandContext.GetEntityStateInEF <HistoricProcessInstanceEventEntity>(data) != EntityState.Detached)
         {
             //TODO dbEntityManager.merge(historyEvent)
             //Context.CommandContext.GetDbEntityManager<HistoricProcessInstanceEventEntity>().Update(data);
             Context.CommandContext.HistoricProcessInstanceManager.Update(data);
         }
         else//不在当前上下文,已经被设置过
         {
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricProcessInstanceManager.Get(data.Id), data);
             //PropertyUpdateHelper.UpDate<HistoricProcessInstanceEventEntity>(Context.CommandContext.GetDbEntityManager<HistoricProcessInstanceEventEntity>().Get(data.Id), data);
         }
     }
     else if
     (historyEvent is HistoricActivityInstanceEventEntity)
     {
         HistoricActivityInstanceEventEntity data = historyEvent as HistoricActivityInstanceEventEntity;
         log.LogDebug("Entity当前状态", Context.CommandContext.GetEntityStateInEF <HistoricActivityInstanceEventEntity>(data).ToString() + " " + data.Id + " " + data.ActivityInstanceState);
         if (Context.CommandContext.GetEntityStateInEF <HistoricActivityInstanceEventEntity>(data) != EntityState.Detached)
         {
             //Context.CommandContext.GetDbEntityManager<HistoricActivityInstanceEventEntity>().Update(data);
             Context.CommandContext.HistoricActivityInstanceManager.Update(data);
         }
         else
         {
             //log.LogDebug("EF更新缓存", typeof(HistoricActivityInstanceEventEntity) + " " + data.Id+" state:"+data.ActivityInstanceState);
             // Todo: Context.CommandContext.GetDbEntityManager<TEntity>()方法有问题
             //var cache = Context.CommandContext.HistoricActivityInstanceManager.Get(data.Id);
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricActivityInstanceManager.Get(data.Id), data);
             //log.LogDebug("测试001", Context.CommandContext.GetDbEntityManager<HistoricActivityInstanceEventEntity>().Get(data.Id).ActivityInstanceState.ToString());
         }
     }
     else if (historyEvent is Event.HistoricTaskInstanceEventEntity)
     {
         Event.HistoricTaskInstanceEventEntity data = historyEvent as Event.HistoricTaskInstanceEventEntity;
         if (Context.CommandContext.GetEntityStateInEF <Event.HistoricTaskInstanceEventEntity>(data) != EntityState.Detached)
         {
             //Context.CommandContext.GetDbEntityManager<Event.HistoricTaskInstanceEventEntity>().Update(data);
             Context.CommandContext.HistoricTaskInstanceManager.Update(data);
         }
         else
         {
             //PropertyUpdateHelper.UpDate<Event.HistoricTaskInstanceEventEntity>(Context.CommandContext.GetDbEntityManager<Event.HistoricTaskInstanceEventEntity>().Get(data.Id), data);
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricTaskInstanceManager.Get(data.Id), data);
         }
     }
     else if (historyEvent is HistoricIncidentEntity)
     {
         HistoricIncidentEntity data = (HistoricIncidentEntity)historyEvent;
         if (Context.CommandContext.GetEntityStateInEF <HistoricIncidentEntity>(data) != EntityState.Detached)
         {
             //Context.CommandContext.GetDbEntityManager<HistoricIncidentEntity>().Update(data);
             Context.CommandContext.HistoricIncidentManager.Update(data);
         }
         else
         {
             //PropertyUpdateHelper.UpDate<HistoricIncidentEntity>(Context.CommandContext.GetDbEntityManager<HistoricIncidentEntity>().Get(data.Id), data);
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricIncidentManager.Get(data.Id), data);
         }
     }
     else
     {
         throw new NotImplementedException(string.Format("historyEvent类型:{0} 更新未实现", historyEvent.GetType().ToString()));
     }
 }