/// <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 IEnumerable <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>
        /// 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 virtual IQueryable <T> FindAll(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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Undoes changes to the current DbContext by removing it from the storage container.
 /// </summary>
 public void Undo()
 {
     DataContextFactory.Clear();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Saves the changes to the underlying DbContext.
 /// </summary>
 public void Dispose()
 {
     DataContextFactory.GetDataContext().SaveChanges();
 }
 /// <summary>
 /// Gets a list of all the people whose last name exactly matches the search string.
 /// </summary>
 /// <param name="lastName">The last name that the system should search for.</param>
 /// <returns>An IEnumerable of Person with the matching people.</returns>
 public IEnumerable <Person> FindByLastName(string lastName)
 {
     return(DataContextFactory.GetDataContext().Set <Person>().Where(x => x.LastName == lastName));
 }
 /// <summary>
 /// Removes an entity from the underlying DbContext.
 /// </summary>
 /// <param name="entity">The entity that should be removed.</param>
 public virtual void Remove(T entity)
 {
     DataContextFactory.GetDataContext().Set <T>().Remove(entity);
 }
 /// <summary>
 /// Adds an entity to the underlying DbContext.
 /// </summary>
 /// <param name="entity">The entity that should be added.</param>
 public virtual void Add(T entity)
 {
     DataContextFactory.GetDataContext().Set <T>().Add(entity);
 }