Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // All the objects in the collection already exist in the database
  2. // so NHibernate should throw an Exception because of a PK constraint
  3. // violation
  4. foreach (var existingEntity in existingEntities)
  5. {
  6. // Implementation calls Session.CreateTransaction(),
  7. // but the interface returns System.Data.IDbTransaction.
  8. // This assembly has no references to NHibernate.
  9. using (var transaction = repo.CreateTransaction())
  10. {
  11. try
  12. {
  13. // Executes a simple insert
  14. repo.SaveComposite(existingEntity);
  15. transaction.Commit();
  16. }
  17. catch (Exception e)
  18. {
  19. transaction.Rollback();
  20.  
  21. // Only record the inner-most message
  22. var innerException = e;
  23. while (innerException.InnerException != null)
  24. innerException = innerException.InnerException;
  25.  
  26. Errors.Add(new Error(ErrorCode.ExceptionOccurred, innerException.Message));
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement