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()); } }
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(); } }
public TEntity Insert <TEntity>(TEntity entity) where TEntity : class { using (var context = DataContextFactory.NewInstance()) { context.Insert(entity); context.SaveChanges(); return(entity); } }
public TEntity Update <TEntity>(TEntity entity) where TEntity : class { using (var context = DataContextFactory.NewInstance()) { context.AttachModified(entity); context.SaveChanges(); return(entity); } }
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))); } }
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()); } }
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()); } }