Custom NPOCO database connection... is this a sane...
# help-with-umbraco
j
I guess this is only tangentially related to Umbraco but the NPOCO docs are a bit sparse and it's not the most popular library in the world. I'm hoping some other lovely Umbracians have experience with this. I've inherited a project I'm upgrading to v13 which uses NPOCO to connect to a different database to Umbraco. From what I can piece together across GitHub comments and Stack Overflow, it looks like the right way to use it is to instantiate and dispose the database object with every request - and rely on .NET's connection pooling to take care of perf... can anyone confirm if this approach is OK?
Copy code
csharp
private IDatabase GetDatabase() => 
    new Database(ConnectionString, DatabaseType.SqlServer2012, SqlClientFactory.Instance);

public async Task<IEnumerable<vessel>> GetAll()
{
    using var database = GetDatabase();

    return await database.FetchAsync<vessel>("SELECT * FROM " + TableName + " ORDER BY Vessel");
}

//... other repository methods
l
This is how I have approached the same thing, also interested if there is a better / different way of doing this.
88 Views