New Q2 Domain Model, missing transaction control?

5 posts, 0 answers
  1. HHalim
    HHalim avatar
    69 posts
    Member since:
    Aug 2005

    Posted 19 Jul 2010 Link to this post

    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.
  2. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 19 Jul 2010 Link to this post

    I believe it's all rolled up into
    .SaveChanges (Commits)
    .ClearChanges (Rollsback)

    So no more need to open a Transaction (Good news really...)
  3. DevCraft banner
  4. HHalim
    HHalim avatar
    69 posts
    Member since:
    Aug 2005

    Posted 20 Jul 2010 Link to this post

    @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!
  5. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 20 Jul 2010 Link to this post

    Same deal as the scope, just dispose the context

    dataModel.Dispose();

    :)


  6. Serge
    Admin
    Serge avatar
    375 posts

    Posted 20 Jul 2010 Link to this post

    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
Back to Top
DevCraft banner