/// <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 IQueryable 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 <TDbContext> .GetDataContext(_httpContextAccessor).Set <T>();

            if (includeProperties != null)
            {
                foreach (var includeProperty in includeProperties)
                {
                    items = items.Include(includeProperty);
                }
            }
            return(items.Where(predicate));
        }
Exemple #2
0
        private bool disposedValue = false;         // To detect redundant calls

        /// <summary>
        /// Saves the changes to the underlying DbContext.
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    DataContextFactory <T> .GetDataContext(_httpContextAccessor).SaveChanges();
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Exemple #3
0
 /// <summary>
 /// Undoes changes to the current DbContext by removing it from the storage container.
 /// </summary>
 public void Undo()
 {
     DataContextFactory <T> .Clear(_httpContextAccessor);
 }
 /// <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 <TDbContext> .GetDataContext(_httpContextAccessor).Set <T>().Remove(entity);
 }
 public virtual void DoNotEdit(T entity)
 {
     DataContextFactory <TDbContext> .GetDataContext(_httpContextAccessor).Entry(entity).State = EntityState.Unchanged;
 }
 public virtual void Edit(T entity)
 {
     DataContextFactory <TDbContext> .GetDataContext(_httpContextAccessor).Entry(entity).State = EntityState.Modified;
 }