Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Created February 4, 2019 11:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warrenbuckley/ff06f8cf1ed98c15b7c7215abd460438 to your computer and use it in GitHub Desktop.
Save warrenbuckley/ff06f8cf1ed98c15b7c7215abd460438 to your computer and use it in GitHub Desktop.
Super simple example of using Database inside Umbraco V8
using Umbraco.Core.Scoping;
namespace My.Website
public class DatabaseExample
{
private IScopeProvider _scopeProvider;
public DatabaseExample(IScopeProvider scopeProvider)
{
_scopeProvider = scopeProvider;
}
public void DoSomething()
{
using (var scope = _scopeProvider.CreateScope())
{
// Scope.Database has what you need/want
scope.Database.Fetch<MyType>("Select * From MyTable");
// You must always complete a scope
scope.Complete();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment