Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // All the objects in the collection already exist in the database
- // so NHibernate should throw an Exception because of a PK constraint
- // violation
- foreach (var existingEntity in existingEntities)
- {
- // Implementation calls Session.CreateTransaction(),
- // but the interface returns System.Data.IDbTransaction.
- // This assembly has no references to NHibernate.
- using (var transaction = repo.CreateTransaction())
- {
- try
- {
- // Executes a simple insert
- repo.SaveComposite(existingEntity);
- transaction.Commit();
- }
- catch (Exception e)
- {
- transaction.Rollback();
- // Only record the inner-most message
- var innerException = e;
- while (innerException.InnerException != null)
- innerException = innerException.InnerException;
- Errors.Add(new Error(ErrorCode.ExceptionOccurred, innerException.Message));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement