Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee 1130 posts 3088 karma points
    Jun 22, 2013 @ 09:15
    Lee
    0

    PetaPoco Umbraco v6 UnitOfWork?

    Does v6 already have it's own UnitOfWork implementation? Or should we be implementing our own to handle transactions and rollbacks etc...

    If so, could you provide an example of how I can use it. Thanks

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 22, 2013 @ 09:22
    Morten Christensen
    100

    We do have an implementation but its centered around the repositories which are all internal. So its not yet exposed in way that makes it usable outside the Core.

    If you want to wrap your data access in a transaction you should just use the transaction that is exposed through PetaPoco.

    If you are working with content through the new API then you just need to know that transactions and UnitOfWork is handled within stuff like the ContentService.

     

    - Morten

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 22, 2013 @ 09:25
    Morten Christensen
    0

    Is it custom data you want to access through PetaPoco?

  • Lee 1130 posts 3088 karma points
    Jun 22, 2013 @ 15:03
    Lee
    0

    Its all custom data I'm using. I found the exposed begin transaction stuff, but I found an IUnitOfWork and thought that might be something we are supposed to use. I'll use the exposed transaction stuff :) Thanks

  • Lee 1130 posts 3088 karma points
    Jun 22, 2013 @ 15:24
    Lee
    0

    If this how I am supposed to use it?

    var _database = ApplicationContext.Current.DatabaseContext.Database;
    using (var uow = _database.Connection.BeginTransaction())
    {
    // Do a commit using this? uow.Commit(); // Do a rollback using this? uow.Rollback();
    }

    If so I get a 'Object reference not set to an instance of an object.' error when I try and use it?

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 22, 2013 @ 15:46
    Morten Christensen
    0

    Almost ... For the transaction use:

    using (var uow = _database.GetTransaction())

    { uow.Complete(); }

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 22, 2013 @ 15:49
    Morten Christensen
    1

    More or less everything you need when using PetaPoco is documentes here: http://www.toptensoftware.com/petapoco/

  • Lee 1130 posts 3088 karma points
    Jun 22, 2013 @ 15:50
    Lee
    0

    But where is the rollback? Or does it do it by itself if you don't call the uow.Complete()?

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 22, 2013 @ 15:56
    Morten Christensen
    0

    If the transaction isn't completed the changes are not committed. If something fails within the using block the transaction isn't committed and if you don't call .completed the transaction isn't committed. As far as I remember Dispose on the transaction calls rollback, but you can check the source of PetaPoco to verify or maybe check the documentation I posted a link to.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 08, 2013 @ 18:26
    Ismail Mayat
    0

    Morten,

    uow.Complete();

    Intellisense is not picking that up am i missing something?

    Regards

    Ismail

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jul 08, 2013 @ 18:32
    Morten Christensen
    2

    Think System and Umbraco.Core.Persistence should be enough.

    When you have the database object its just:

    using(var transaction = database.GetTransaction())
    { .... transaction.Complete(); }

    Hope this helps

    - Morten

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 08, 2013 @ 18:47
    Ismail Mayat
    0

    bingo ta

  • Karan Sehgal 1 post 21 karma points
    Dec 24, 2013 @ 14:27
    Karan Sehgal
    0

    We are using PetaPoco db framework with shared connection. But we are getting following error:

    ExecuteReader requires an open and available Connection. The connection's current state is connecting.

    and many of times getting shared connection object null in "_sharedConnection.Open()".

     

      public void OpenSharedConnection()        {

                if (_sharedConnectionDepth == 0)            {

                    _sharedConnection = _factory.CreateConnection();

                    _sharedConnection.ConnectionString = _connectionString;

                   if (_sharedConnection.State == ConnectionState.Broken)

                       _sharedConnection.Close();

                    if (_sharedConnection.State == ConnectionState.Closed)

                        _sharedConnection.Open();

                   _sharedConnection = OnConnectionOpened(_sharedConnection);

                    if (KeepConnectionAlive)

                        _sharedConnectionDepth++;// Make sure you call Dispose

                }

                _sharedConnectionDepth++;

            }

     

    Is anyone help me to let out this issue? 

    Thanks in advance!

Please Sign in or register to post replies

Write your reply to:

Draft