public PhotoAlbumEntities GetCurrent()
 {
     if (HttpContext.Current.Items[httpContextKey] == null)
     {
         PhotoAlbumEntities context = new PhotoAlbumEntities();
         context.Connection.Open();
         HttpContext.Current.Items.Add(httpContextTransactionKey, context.Connection.BeginTransaction());
         HttpContext.Current.Items.Add(httpContextKey, context);
     }
     return((PhotoAlbumEntities)HttpContext.Current.Items[httpContextKey]);
 }
 void context_EndRequest(object sender, EventArgs e)
 {
     if (HttpContext.Current.Items[httpContextKey] != null)
     {
         using (PhotoAlbumEntities context = (PhotoAlbumEntities)HttpContext.Current.Items[httpContextKey])
         {
             Boolean RollbackRequested = (Boolean)(HttpContext.Current.Items[rollbackRequestedKey] ?? false);
             using (DbTransaction transaction = (DbTransaction)HttpContext.Current.Items[httpContextTransactionKey])
             {
                 if (RollbackRequested)
                 {
                     transaction.Rollback();
                 }
                 else
                 {
                     context.SaveChanges();
                     transaction.Commit();
                 }
             }
         }
     }
 }