This is a migrated thread and some comments may be shown as answers.

New Q2 Domain Model, missing transaction control?

4 Answers 63 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
HHalim
Top achievements
Rank 2
HHalim asked on 19 Jul 2010, 08:43 PM
Hello,
With the new Domain Model in Q2 version, how do you control transaction?

I created a new test project with an existing database and the new Domain Model does not have ObjectScope provider, so how do you start, commit, rollback changes in the transaction? Where is the dispose function for the data model context?

For example, how do you rollback after an error in an edit action, such as:
var dataModel = DbContextFactory.GetContextPerRequest(this.Context);
var inID = Convert.ToInt32(TestID.Text);
var tests = from t in dataModel.Tests where t.TestID == inID select t;
 
using (dataModel)
{
var entity = tests.First();
entity.Value = "Edited " + DateTime.Now;
dataModel.SaveChanges();
}

Thanks.

4 Answers, 1 is accepted

Sort by
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 20 Jul 2010, 02:12 AM
I believe it's all rolled up into
.SaveChanges (Commits)
.ClearChanges (Rollsback)

So no more need to open a Transaction (Good news really...)
0
HHalim
Top achievements
Rank 2
answered on 20 Jul 2010, 04:06 PM
@Steve: That's good to hear it is much streamlined now, not much information in the help document about transaction handling.

Also, no clear explanation about the dispose function, how do you dispose the context model or connection object, it used to be that you have to manually do a ObjectScope.dispose(), or is this something automatically handled also?

Thanks!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 20 Jul 2010, 04:08 PM
Same deal as the scope, just dispose the context

dataModel.Dispose();

:)


0
Serge
Telerik team
answered on 20 Jul 2010, 06:23 PM
Hello Hartono and hello Steve,

 First of all, Steve you are absolutely correct, there is in fact no need to start the transaction and right now the SaveChanges() corresponds to the old Commit() and ClearChanges() to Rollback(). 

As to the dispose you will see that your context class (the dataModel instance in the example provided) implements the IDisposable interface which means that you can dispose it by simple calling dataModel.Dispose() or put it in a using block as you have in the example you have provided.

Be sure to contact us back if you need further information.

All the best,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Getting Started
Asked by
HHalim
Top achievements
Rank 2
Answers by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
HHalim
Top achievements
Rank 2
Serge
Telerik team
Share this question
or