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?
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With