Пример #1
0
 /// <summary>
 ///     Disposes the underlying data context.
 /// </summary>
 public void Dispose()
 {
     if (DataContextFactory.GetDataContext() != null)
     {
         DataContextFactory.GetDataContext().Dispose();
     }
 }
Пример #2
0
 /// <summary>
 /// Saves the changes to the underlying DbContext.
 /// </summary>
 /// <param name="resetAfterCommit">When true, clears out the data context afterwards.</param>
 public void Commit(bool resetAfterCommit)
 {
     DataContextFactory.GetDataContext().SaveChanges();
     if (resetAfterCommit)
     {
         DataContextFactory.Clear();
     }
 }
Пример #3
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));
        }
Пример #4
0
 /// <summary>
 /// Saves the changes to the underlying DbContext.
 /// </summary>
 public void Dispose()
 {
     DataContextFactory.GetDataContext().SaveChanges();
 }
Пример #5
0
 public T Update(T entity)
 {
     DataContextFactory.GetDataContext().Entry(entity).State = EntityState.Modified;
     return(entity);
 }
Пример #6
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);
 }
Пример #7
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));
 }
Пример #8
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);
        }
Пример #9
0
 public IQueryable <T> FindBy(Expression <Func <T, bool> > predicate)
 {
     return(DataContextFactory.GetDataContext().Set <T>().Where(predicate));
 }