Can you get the DbContext from a DbSet?

With Entity Framework Core (tested with Version 2.1) you can get the current context using

// DbSet<MyModel> myDbSet
var context = myDbSet.GetService<ICurrentDbContext>().Context;

How to get a DbContext from a DbSet in EntityFramework Core 2.0

Leave a Comment