In this recipe, we will learn how to create a new EF provider. It can be used to create a relational or a nonrelational provider.
We will import the Microsoft.EntityFrameworkCore.Relational
library in project.json
or NuGet.
- First, let's get some sample code to override, and which allows us to create a new EF provider. We can find the template at https://github.com/aspnet/EntityFramework.Docs/tree/master/docs/internals/sample.
- Next, we can add this new provider by creating an extension method on
DbContextOptionBuilder
as follows:
public static class MyProviderDbContextOptionsExtensions { public static DbContextOptionsBuilder UseMyProvider( this DbContextOptionsBuilder optionsBuilder, string connectionString) { ((IDbContextOptionsBuilderInfrastructure)optionsBuilder) .AddOrUpdateExtension( new MyProviderOptionsExtension { ConnectionString = connectionString }); return optionsBuilder; } }
The UseMyProvider()
method can also be used to...