riccardocagnasso

Untitled

Jan 16th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1.         /// <summary>
  2.         /// This reloads a model from a (new) context, this serves to different
  3.         /// porpouses.
  4.         ///
  5.         /// First we need a model class attached to a current context to perform
  6.         /// many operations (navigating relations, delete, edit etc..)
  7.         ///
  8.         /// Second we need to check if the model object was not deleted from the
  9.         /// database in the meantime.
  10.         ///
  11.         /// Third we will do some concurrency check. If an object in the database
  12.         /// was modified elsewhere, we won't do any operation and raise a ConcurrentChangeException
  13.         ///
  14.         /// I'm not completely entirely sure that this is what is required for Concurrency
  15.         /// Management, some parts of the specifications seems to imply that like
  16.         ///
  17.         /// "Any detected attempt to save an entity on the DB which has been concurrently modified must be communicated throwing ConcurrentChangeException"
  18.         ///
  19.         /// some thread on the other hand seems to deny this, like
  20.         ///
  21.         /// http://dibris.aulaweb.unige.it/mod/forum/discuss.php?d=5679
  22.         /// "non ci sono test automatici per il comportamento concorrente (e non ne posso fare se testo attraverso l'interfaccia)"
  23.         ///
  24.         /// http://dibris.aulaweb.unige.it/mod/forum/discuss.php?d=5631
  25.         /// "Qualsiasi sistema ragionevole che usa la componente non dovrebbe mai avere due oggetti distinti che rappresentano la
  26.         /// stessa entità. Pertanto, non ci si dovrebbe mai trovare nella situazione di avere due oggetti A e B che rappresentano entrambi
  27.         /// la stessa entità E e voler accedere a metodo/proprietà su A dopo aver invocato Delete su B. Per questa ragione la specifica non
  28.         /// dettaglia bene che cosa dovrebbe succedere (perché non dovrebbe succedere)
  29.         ///
  30.         /// </summary>
  31.         /// <param name="context"></param>
  32.         public virtual void RefreshModel(AuctionContext context)
  33.         {
  34.             var newModel = this.GetModel(context);
  35.  
  36.             if (((IConcurrencyEnabled)this.Model).RowVersion < ((IConcurrencyEnabled)newModel).RowVersion)
  37.             {
  38.                 throw new ConcurrentChangeException();
  39.             }
  40.             else
  41.             {
  42.                 this.Model = newModel;
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment