mehdime / DbContextScope

A simple and flexible way to manage your Entity Framework DbContext instances
http://mehdi.me/ambient-dbcontext-in-ef6/
MIT License
634 stars 271 forks source link

Unable to use a non-interfaced DbContext with DbContextScope #53

Closed starmandeluxe closed 5 years ago

starmandeluxe commented 7 years ago

I am using .NET Core 1.1 and EF Core, in which my MyDbContext simply inherits from EntityFrameworkCore.DbContext. Unfortunately, DbContextScope expects only an EntityFramework.DbContextScope.IDbContext. How do I resolve this?

I tried implementing the OnConfiguring method in MyDbContext and manually provided the connection string, and while this does get it working, I don't like having to provide the connection string inside there since it's being handled by .NET Core's Startup.cs already:

services.AddDbContext<MyDbContext>(options => options.UseSqlServer("connection string here"));

tiesont commented 7 years ago

This library isn't really built to work with .NET Core, although I assume some people have managed to make it work. You might want to check out a fork that (in theory) has been updated to work with Core: https://github.com/apawsey/DbContextScope

Disclaimer: I haven't had a need to move to .NET Core yet, so I don't have any first-hand experience with what does and what doesn't work.

starmandeluxe commented 7 years ago

Hmmm, actually I checked in Nuget Manager and that's precisely the fork I have installed currently. I will post this question on his fork instead.