Error Testing Custom EF Core Connection: Pomelo.EntityFrameworkCore.MySql v3.2.4
I have a .NET Standard 2.0 project that contains an EF Core 3.1.12 context (latest version that still supports .NET Standard 2.0 to support .NET Framework). I am using the Pomelo.EntityFrameworkCore.MySql v3.2.4 provider.
I am trying to setup a LinqPad 6 connection using, "a constructor that accepts a DbContextOptions" since I have a web.config file and not a appsettings.json.
I am currently getting the following error.
DbContext options is in Microsoft.EntityFrameworkCore and not the Pomelo provider so that makes sense. Is there a known resolution to this?
I did find this forum discussion that seems related but I have tried the latest beta version with no success.
https://forum.linqpad.net/discussion/2306/invalidoperationexception-with-efcore-5-connection-that-uses-pomelo-driver-and-dbcontextoptions
Comments
Microsoft's pattern of using DbContextOptions to construct a data context requires that LINQPad jump through a series of continually moving hoops. Needless to say, it's time-consuming and frustrating to support.
A workaround, when it fails, is to define an additional constructor on your DbContext - either a parameterless constructor or a constructor that accepts a string. For more information, click the "Help me choose" hyperlink on the connection. This will take you to the following example:
https://linqpad.azureedge.net/public/SampleDbContext.cs
Are there current plans to eventually support this configuration or to support specifying a web.config file instead of a appsettings.json file?
The web.config file was phased out in .NET Core 3, and has been deprecated in favor of appsettings.json:
https://docs.microsoft.com/en-us/aspnet/core/migration/configuration?view=aspnetcore-5.0