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.
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
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?
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.
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
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
Is it custom data you want to access through PetaPoco?
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
If this how I am supposed to use it?
If so I get a 'Object reference not set to an instance of an object.' error when I try and use it?
Almost ... For the transaction use:
using (var uow = _database.GetTransaction())
{ uow.Complete(); }
More or less everything you need when using PetaPoco is documentes here: http://www.toptensoftware.com/petapoco/
But where is the rollback? Or does it do it by itself if you don't call the uow.Complete()?
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.
Morten,
uow.Complete();
Intellisense is not picking that up am i missing something?
Regards
Ismail
Think System and Umbraco.Core.Persistence should be enough.
When you have the database object its just:
Hope this helps
- Morten
bingo ta
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!
is working on a reply...