Usage of NPoco in .net Core
Asked Answered
T

1

6

I have recently started diving into the new .net core along with asp.net core mvc. There have been several issues that I have come across but have been able to get most of them answered on my own. The one that has really stumped me is the use of NPoco.

How are you supposed to create the database instance?

The documentation reads:

IDatabase db = new Database("connStringName");
List<User> users = db.Fetch<User>("select userId, email from users");

This is not correct for DNXCORE50 as this constructor has been excluded for DNCORE50

I have also attempted this:

IDatabase _db = new Database(new SqlConnection(ConnStr));
_db.Single<string>("SELECT Username FROM dbo.Member");

When this code is ran I get a 'NullReferenceException'

Does anyone know how to get NPoco working properly?

Takashi answered 15/6, 2016 at 15:0 Comment(0)
T
1

There are other people having the same issue. This has been reported as issue #293 on NPoco GitHub repository.

The current workaround for this problem is to list the DbProviderFactory as shown below.

IDatabase _db = new Database(new SqlConnection(ConnStr),
                             DatabaseType.SqlServer2012, SqlClientFactory.Instance);
_db.Single<string>("SELECT Username FROM dbo.Member")
Takashi answered 22/6, 2016 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.