예제 #1
0
        public static T CacheLoad <T>(int id, params Expression <Func <T, object> >[] includes) where T : class, ICacheable
        {
            var w      = WorkspaceFactory.Create();
            var entity = w.Single(x => x.Id == id, includes);

            AddToEntityCache <T>(entity, w);

            return(entity);
        }
예제 #2
0
        public static string GetConnectionString()
        {
            string connectionString;

            using (IWorkspace workspace = WorkspaceFactory.Create())
            {
                connectionString = workspace.GetConnectionString();
            }
            return(connectionString);
        }
예제 #3
0
 public static void ExecSqlCommand(string commandText, params object[] parameters)
 {
     using (IWorkspace workspace = WorkspaceFactory.Create())
     {
         foreach (string str in Executor.FixCommandText(commandText))
         {
             workspace.ExecSql(Executor.GetCommand(str, parameters));
         }
     }
 }
예제 #4
0
 public static void SafeSave <T>(T entity) where T : class, IEntityClass
 {
     using (var w = WorkspaceFactory.Create())
     {
         AddEntities(entity, w, entity.Id);
         if (entity.Id == 0)
         {
             w.Add(entity);
         }
         else
         {
             var currentItem = w.Single <T>(x => x.Id == entity.Id);
             currentItem.InjectFrom <EntityInjection>(entity);
         }
         w.CommitChanges();
     }
 }
예제 #5
0
        public static string CheckConcurrency <T>(T entity) where T : class, ICacheable
        {
            var lup = Dao.Single <T, DateTime>(entity.Id, x => x.LastUpdateTime);

            if (entity.LastUpdateTime.CompareTo(lup) == 0)
            {
                return("");
            }

            using (var w = WorkspaceFactory.Create())
            {
                var loaded = w.Single <T>(x => x.Id == entity.Id);
                var cr     = ValidatorRegistry.GetConcurrencyErrorMessage(entity, loaded);
                if (cr.SuggestedOperation == SuggestedOperation.Refresh)
                {
                    RemoveFromEntityCache(entity);
                }
                return(cr.ErrorMessage);
            }
        }
예제 #6
0
        public static void CacheSave <T>(T entity) where T : class, ICacheable
        {
            if (entity.Id > 0)
            {
                var ce = GetFromEntitiyCache <T>(entity.Id);
                if (ce != null)
                {
                    if (ce.Cacheable != entity)
                    {
                        ce.Cacheable.InjectFrom <EntityInjection>(entity);
                    }
                    entity.LastUpdateTime = DateTime.Now;
                    AddEntities(ce.Cacheable, ce.Workspace, entity.Id);
                    ce.Workspace.CommitChanges();
                    RemoveFromEntityCache <T>(ce);
                    return;
                }
            }

            if (entity.Id == 0)
            {
                var w = WorkspaceFactory.Create();
                AddEntities(entity, w, entity.Id);
                w.Add(entity);
                entity.LastUpdateTime = DateTime.Now;
                w.CommitChanges();
                AddToEntityCache <T>(entity, w);
            }
            else
            {
                using (var w = WorkspaceFactory.Create())
                {
                    var currentItem = w.Single <T>(x => x.Id == entity.Id);
                    currentItem.InjectFrom <EntityInjection>(entity);
                    entity.LastUpdateTime = DateTime.Now;
                    AddEntities(currentItem, w, entity.Id);
                    w.CommitChanges();
                }
            }
        }