Пример #1
0
        public static IQueryable <TActivatedEntity> GetActiveEntities <TActivatedEntity>(this IPersistentService persistentService)
            where TActivatedEntity : class, IEntity, IActivatedEntity, new()
        {
            CheckHelper.ArgumentNotNull(persistentService, "persistentService");

            return
                (persistentService
                 .GetEntitySet <TActivatedEntity>()
                 .Where(e => e.Active));
        }
Пример #2
0
        public static void Add <TEntity>(this IPersistentService persistentService, TEntity entity)
            where TEntity : class, IEntity, new()
        {
            CheckHelper.ArgumentNotNull(persistentService, "persistentService");
            CheckHelper.ArgumentNotNull(entity, "entity");

            persistentService
            .GetEntitySet <TEntity>()
            .Add(entity);
        }
Пример #3
0
        public static TEntity GetEntityById <TEntity>(this IPersistentService persistentService, int id)
            where TEntity : class, IEntity, new()
        {
            CheckHelper.ArgumentNotNull(persistentService, "persistentService");
            CheckHelper.ArgumentWithinCondition(id > 0, "id > 0");

            return
                (persistentService
                 .GetEntitySet <TEntity>()
                 .SingleOrDefault(e => e.Id == id));
        }
        private static void SetIds <TEntity>(IPersistentService persistentService)
            where TEntity : class, IEntity, new()
        {
            var entities    = persistentService.GetEntitySet <TEntity>().ToArray();
            var newEntities = entities.Where(e => e.IsNew()).ToArray();

            if (newEntities.Any())
            {
                var maxId = entities.Max(e => e.Id);

                foreach (var newEntity in newEntities)
                {
                    newEntity.Id = ++maxId;
                }
            }
        }