Пример #1
0
 public User GetUserUncommitted(Guid userId)
 {
     /*
      * An example of explicit database transaction.
      *
      * Read the comment for CreateReadOnlyWithTransaction() before using this overload
      * as there are gotchas when doing this!
      */
     using (_dbContextScopeFactory.CreateReadOnlyWithTransaction(IsolationLevel.ReadUncommitted)) {
         return(_userRepository.Get(userId));
     }
 }
        /// <summary>
        /// Temporarily suppresses the ambient DbContextScope.
        /// Always use this if you need to  kick off parallel tasks within a DbContextScope.
        /// This will prevent the parallel tasks from using the current ambient scope. If you
        /// were to kick off parallel tasks within a DbContextScope without suppressing the ambient
        /// context first, all the parallel tasks would end up using the same ambient DbContextScope, which
        /// would result in multiple threads accesssing the same DbContext instances at the same
        /// time.
        /// </summary>
        public static TDbContext OpenReadOnly <TDbContext>(this IDbContextScopeFactory self, IsolationLevel isolationLevel) where TDbContext : DbContext
        {
            var dbContextScope = self.CreateReadOnlyWithTransaction(isolationLevel);

            return(dbContextScope.Get <TDbContext>());
        }