示例#1
0
        /// <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));
        }
示例#2
0
 /// <summary>
 /// Undoes changes to the current DbContext by removing it from the storage container.
 /// </summary>
 public void Undo()
 {
     DataContextFactory.Clear();
 }
示例#3
0
 /// <summary>
 /// Saves the changes to the underlying DbContext.
 /// </summary>
 public void Dispose()
 {
     DataContextFactory.GetDataContext().SaveChanges();
 }
示例#4
0
 public T Update(T entity)
 {
     DataContextFactory.GetDataContext().Entry(entity).State = EntityState.Modified;
     return(entity);
 }
示例#5
0
 /// <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);
 }
示例#6
0
 /// <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));
 }
示例#7
0
        /// <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);
        }
示例#8
0
 public IQueryable <T> FindBy(Expression <Func <T, bool> > predicate)
 {
     return(DataContextFactory.GetDataContext().Set <T>().Where(predicate));
 }