Created
February 4, 2019 11:12
-
-
Save warrenbuckley/ff06f8cf1ed98c15b7c7215abd460438 to your computer and use it in GitHub Desktop.
Super simple example of using Database inside Umbraco V8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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