This is a migrated thread and some comments may be shown as answers.
Database fixture problem
5 Answers 74 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alexey
Top achievements
Rank 2
Alexey asked on 10 Nov 2008, 10:14 AM
When i was using NHibernate and Linq to SQL I've created database fixture, which rollbacks database changes 
after each test.

    public class DatabaseFixture : IDisposable
    {
        private readonly TransactionScope transactionScope;

        protected DatabaseFixture()
        {
            transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew);
        }

        #region IDisposable Members

        public void Dispose()
        {
            transactionScope.Dispose();
        }

        #endregion
    }
But now it doesn't rollbacks changes made on object scope transaction commit. Any ideas how to get it work =)


5 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 10 Nov 2008, 11:11 AM
Hi Alexey,

You should not use the scope.Transaction, you have to change the transaction properties of your database so that we integrate us into system.transactions:

database.Properties.TransactionProvider = TransactionProvider.TransactionScope;

Greetings,
Jan Blessenohl
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alexey
Top achievements
Rank 2
answered on 10 Nov 2008, 01:29 PM
But if want to use scope transaction. How can i implement such database fixture (It should rollback any changes within database made during the test)?


0
Jan Blessenohl
Telerik team
answered on 10 Nov 2008, 02:47 PM
Hi Alexey,

You can only do it in the same way. just set the property at Database and use your code as it is.

Kind regards,
Jan Blessenohl
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alexey
Top achievements
Rank 2
answered on 10 Nov 2008, 03:17 PM
Also Open Access Transaction has Level property which determinate nesting level. But I don't understand how we can create nested transactions? There is nothing said about it in documentation.
0
Jan Blessenohl
Telerik team
answered on 11 Nov 2008, 09:59 AM
Hello Alexey,

Nested transactions are not supported at the moment. The level can only be 0 and 1.

Best wishes,
Jan Blessenohl
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Alexey
Top achievements
Rank 2
Answers by
Jan Blessenohl
Telerik team
Alexey
Top achievements
Rank 2
Share this question
or