public virtual IList <T> GetList(Func <T, bool> where, params Expression <Func <T, object> >[] navigationProperties) { List <T> list; try { using (var context = new WebPresenceEntities()) { IQueryable <T> dbQuery = context.Set <T>(); foreach (Expression <Func <T, object> > navigationProperty in navigationProperties) { dbQuery = dbQuery.Include(navigationProperty); } list = dbQuery .AsNoTracking() .Where(where) .ToList(); return(list); } } catch (Exception ex) { LogManager.Instance.Log(string.Format(DataMesages.DataError, ex.Message, typeof(T).FullName), ex, LoggingLevel.Error); return(null); } }
public virtual T GetSingle(Func <T, bool> where, params Expression <Func <T, object> >[] navigationProperties) { T item = null; try { using (var context = new WebPresenceEntities()) { IQueryable <T> dbQuery = context.Set <T>(); foreach (Expression <Func <T, object> > navigationProperty in navigationProperties) { dbQuery = dbQuery.Include <T, object>(navigationProperty); } item = dbQuery .AsNoTracking() //Don't track any changes for the selected item .FirstOrDefault(where); //Apply where clause } return(item); } catch (Exception ex) { LogManager.Instance.Log(string.Format(DataMesages.DataError, ex.Message, typeof(T).FullName), ex, LoggingLevel.Error); return(null); } }