예제 #1
0
        public bool Exists <TEntity>(Func <TEntity, bool> criteria = null) where TEntity : class
        {
            using (var context = DataContextFactory.NewInstance())
            {
                var query = context.Query <TEntity>();

                return(criteria != null?query.Any(criteria) : query.Any());
            }
        }
예제 #2
0
 public void Delete <TKey, TEntity>(string keyPropertyName, TKey key) where TEntity : class
 {
     using (var context = DataContextFactory.NewInstance())
     {
         var entity = context.Query <TEntity>().Single(GetSelectByKeyCriteria <TKey, TEntity>(keyPropertyName, key));
         context.Delete(entity);
         context.SaveChanges();
     }
 }
예제 #3
0
        public TEntity Insert <TEntity>(TEntity entity) where TEntity : class
        {
            using (var context = DataContextFactory.NewInstance())
            {
                context.Insert(entity);
                context.SaveChanges();

                return(entity);
            }
        }
예제 #4
0
        public TEntity Update <TEntity>(TEntity entity) where TEntity : class
        {
            using (var context = DataContextFactory.NewInstance())
            {
                context.AttachModified(entity);
                context.SaveChanges();

                return(entity);
            }
        }
예제 #5
0
        public TEntity GetByKey <TKey, TEntity>(string keyPropertyName, TKey key, params Expression <Func <TEntity, object> >[] paths) where TEntity : class
        {
            using (var context = DataContextFactory.NewInstance())
            {
                var query = context.Query <TEntity>();
                query = IncludePaths(paths, query);

                return(query.Single(GetSelectByKeyCriteria <TKey, TEntity>(keyPropertyName, key)));
            }
        }
예제 #6
0
        public int Count <TEntity>(Func <TEntity, bool> criteria = null) where TEntity : class
        {
            using (var context = DataContextFactory.NewInstance())
            {
                var query = context.Query <TEntity>();

                if (criteria != null)
                {
                    query = query.Where(criteria).AsQueryable();
                }

                return(query.Count());
            }
        }
예제 #7
0
        public TEntity GetSingle <TEntity>(Func <TEntity, bool> criteria = null, params Expression <Func <TEntity, object> >[] paths) where TEntity : class
        {
            using (var context = DataContextFactory.NewInstance())
            {
                var query = context.Query <TEntity>();
                query = IncludePaths(paths, query);
                if (criteria != null)
                {
                    query = query.Where(criteria).AsQueryable();
                }

                return(query.SingleOrDefault());
            }
        }