public virtual void Delete(Expression <Func <T, bool> > predicate) { AppLogger.logDebug(this.ToString(), string.Format("Begin deleting entities of {0}.", typeof(T))); AppLogger.logDebug(this.ToString(), string.Format("Expression: '{0}'.", predicate.Body.ToString())); try { if (predicate != null) { IEnumerable <T> entities = EntitiesSet.Where(predicate); AppLogger.logDebug(this.ToString(), string.Format("Count: {0}", entities.Count())); foreach (T entity in entities) { AppLogger.logDebug(this.ToString(), "DELETE", entity); Context.DeleteObject(entity); } AppLogger.logDebug(this.ToString(), string.Format("Deleted entities of {0} successfully.", typeof(T))); } } catch (Exception ex) { AppLogger.logError(this.ToString(), string.Format("Error occurs while deleting entities of {0}. Predicate: '{1}'.", typeof(T), predicate.Body.ToString()), ex); throw; } AppLogger.logDebug(this.ToString(), string.Format("Finish deleting entities of {0}.", typeof(T))); }
public async Task <Comment> GetOneWithSubComment(Expression <Func <Comment, bool> > condition) { var comment = await EntitiesSet.Where(condition) .Include(c => c.SubComments) .FirstOrDefaultAsync(); return(comment); }
public async Task <IEnumerable <Comment> > GetManyWithSubComment(Expression <Func <Comment, bool> > condition) { var comments = await EntitiesSet.Where(condition) .Include(c => c.SubComments) .ToListAsync(); return(comments); }
public async Task <LevelTest> GetOneWithQuestionsAndAnswerOptions(int id) { var levelTest = await EntitiesSet.Where(t => t.Id == id && t.IsDeleted != true) .Include(t => t.Questions) .ThenInclude(q => q.AnswerOptions).FirstOrDefaultAsync(); return(levelTest); }
public async Task <IEnumerable <LevelTest> > GetAllWithQuestionsAndOptions() { var levelTests = await EntitiesSet.Where(t => t.IsDeleted != true) .Include(t => t.Questions) .ThenInclude(q => q.AnswerOptions).ToListAsync(); return(levelTests); }
public IQueryable <TDbEntity> Find(Expression <Func <TDbEntity, bool> > filter = null) { return(filter == null ? EntitiesSet : EntitiesSet.Where(filter)); }
public IQueryable <File> FilesByIds(IEnumerable <Guid> ids) { return(EntitiesSet.Where(x => ids.Contains(x.Id))); }
public async Task <Message> GetLastedMessage(int conversationId) { var message = await EntitiesSet.Where(m => m.ConversationId == conversationId).OrderByDescending(s => s.CreatedDate).FirstOrDefaultAsync(); return(message); }