public virtual IQueryable <TEntity> Queryable(bool containsDeleted = false) { try { IQueryable <TEntity> query = _dbSet.AsNoTracking(); if (containsDeleted) { return(query); } else { if (query is IQueryable <ILogicalDeletable> ) { Expression <Func <TEntity, bool> > deleteClause = x => !((ILogicalDeletable)x).IsDeleted; deleteClause = (Expression <Func <TEntity, bool> >)RemoveCastsVisitor.Visit(deleteClause); return(query.Where(deleteClause)); } return(_dbSet.AsNoTracking().AsQueryable()); } } catch (Exception ex) { throw new DataAccessException(ex.Message, ex); } }
public virtual TEntity Find(int id) { try { IQueryable <TEntity> query = _dbSet.AsNoTracking(); if (query is IQueryable <ILogicalDeletable> ) { var logicalDeletedQuery = query as IQueryable <ILogicalDeletable>; Expression <Func <TEntity, bool> > deleteClause = x => !((ILogicalDeletable)x).IsDeleted; deleteClause = (Expression <Func <TEntity, bool> >)RemoveCastsVisitor.Visit(deleteClause); return(query.Where(deleteClause).Where(e => e.ID == id).SingleOrDefault()); } return(query.Where(e => e.ID == id).SingleOrDefault()); } catch (Exception ex) { throw new DataAccessException(ex.Message, ex); } }