/// <summary> /// Returns an IQueryable of items of type T. /// </summary> /// <param name="predicate">A predicate to limit the items being returned.</param> /// <param name="includeProperties"> /// An expression of additional properties to eager load. For example: x => /// x.SomeCollection, x => x.SomeOtherCollection. /// </param> /// <returns>An IEnumerable of the requested type T.</returns> public IQueryable <T> FindAll(Expression <Func <T, bool> > predicate, params Expression <Func <T, object> >[] includeProperties) { IQueryable <T> items = DataContextFactory.GetDataContext().Set <T>(); if (includeProperties != null) { foreach (var includeProperty in includeProperties) { items = items.Include(includeProperty); } } return(items.Where(predicate)); }
/// <summary> /// Undoes changes to the current DbContext by removing it from the storage container. /// </summary> public void Undo() { DataContextFactory.Clear(); }
/// <summary> /// Saves the changes to the underlying DbContext. /// </summary> public void Dispose() { DataContextFactory.GetDataContext().SaveChanges(); }
public T Update(T entity) { DataContextFactory.GetDataContext().Entry(entity).State = EntityState.Modified; return(entity); }
/// <summary> /// Removes an entity from the underlying DbContext. /// </summary> /// <param name="entity">The entity that should be removed.</param> public void Remove(T entity) { DataContextFactory.GetDataContext().Set <T>().Remove(entity); }
/// <summary> /// Adds ab entity to underlying DbContext /// </summary> /// <param name="entity">the entity that sould be added</param> /// <returns></returns> public T Add(T entity) { return(DataContextFactory.GetDataContext().Set <T>().Add(entity)); }
/// <summary> /// Returns an IQueryable of all items of type T. /// </summary> /// <param name="includeProperties"> /// An expression of additional properties to eager load. For example: x => /// x.SomeCollection, x => x.SomeOtherCollection. /// </param> /// <returns>An IQueryable of the requested type T.</returns> public IQueryable <T> FindAll(params Expression <Func <T, object> >[] includeProperties) { IQueryable <T> items = DataContextFactory.GetDataContext().Set <T>(); return(items); }
public IQueryable <T> FindBy(Expression <Func <T, bool> > predicate) { return(DataContextFactory.GetDataContext().Set <T>().Where(predicate)); }