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); }
public static string GetConnectionString() { string connectionString; using (IWorkspace workspace = WorkspaceFactory.Create()) { connectionString = workspace.GetConnectionString(); } return(connectionString); }
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)); } } }
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(); } }
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); } }
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(); } } }