The "cumbersome" using and Complete() stuff is there for safety, mostly for when database updates fail and need to be rolled back.
For querying, use IUmbracoDatabaseFactory and make sure to dispose after usage so you don't keep connections to the db open. I don't know if NPoco's Database class doesn't dispose either, so you will in all cases need that using stuff. :)
Getting the Database in v8
How can I get the database in v8?
In v7 I can find it in
ApplicationContext.Current.DatabaseContext.Database
Hi Soren
From a conversation here: https://github.com/umbraco/UmbracoDocs/issues/745
I'm deducing the Database is now available via a scope object?
eg
??
but is a bit of a guess.
regards
marc
Thanks Marc, that seems to work :)
Also used this
var db = new Database("umbracoDbDsn");
but I guess a magic string is bad practice, and maybe also storing the database in a variable?It just feels cumbersome to do all that
using and Complete() stuff
whenever I need something from the database.Do read this comment from Stephane,
https://github.com/umbraco/Umbraco-CMS/issues/3866#issuecomment-466907932
The "cumbersome"
using and Complete() stuff
is there for safety, mostly for when database updates fail and need to be rolled back.For querying, use
IUmbracoDatabaseFactory
and make sure to dispose after usage so you don't keep connections to the db open. I don't know if NPoco'sDatabase
class doesn't dispose either, so you will in all cases need thatusing stuff
. :)Kevin jump answered this to me in this post
https://our.umbraco.com/forum/umbraco-8/95939-create-custom-tables-migration-umbracodatabase-npoco#comment-303475
is working on a reply...