EntityFramework.Docs
EntityFramework.Docs copied to clipboard
Document the internal/external service provider separation
I am using ef core 3.0 Preview 3 when executing "Add-migration" to add migration, I receive this error:
UseNetTopologySuite requires AddEntityFrameworkSqlServerNetTopologySuite to be called on the internal service provider used.
please help me
this is my project Dependencies:

@nikkhoo63 - This seems like a product issue. Can you provide repro solution/steps?
I just hit the same issue. If I run "dotnet ef migrations add..." I get the following error
UseNetTopologySuite requires AddEntityFrameworkSqlServerNetTopologySuite to be called on the internal service provider used.
I'm using
- Microsoft.EntityFrameworkCore.Design 3.1.1
- Microsoft.EntityFrameworkCore 3.1.1
- Microsoft.EntityFrameworkCore.SqlServer 3.1.1

Worth mentioning that if I remove options.UseInternalServiceProvider(sp); from the screenshot above, the migration works but I get the following warning.
Microsoft.EntityFrameworkCore.Infrastructure[10410] 'AddEntityFramework*' was called on the service provider, but 'UseInternalServiceProvider' wasn't called in the DbContext options configuration. Remove the 'AddEntityFramework*' call as in most cases it's not needed and might cause conflicts with other products and services registered in the same service provider.
I also getting this warning and I don't know what is causing it. Can someone share some light on this matter.
Microsoft.EntityFrameworkCore.Infrastructure[10410] 'AddEntityFramework*' was called on the service provider, but 'UseInternalServiceProvider' wasn't called in the DbContext options configuration. Remove the 'AddEntityFramework*' call as in most cases it's not needed and might cause conflicts with other products and services registered in the same service provider.
Code if it helps:
//Startup:ConfigureServices
services.AddEntityFrameworkSqlServer(); //Also comment this one, but no change.
services.AddEntityFrameworkNpgsql().AddDbContext<Db3CXContext>((sp, options) =>
{
options.UseNpgsql(connString3CX);
options.UseInternalServiceProvider(sp); //Just trying if this helps, but it doesn't
});
services.AddDbContext<MasterContext>(options =>
{
options.UseSqlServer(connStringMaster, b => b.MigrationsAssembly("Web.Hosting"));
if (environment.IsDevelopment())
options.EnableSensitiveDataLogging();
});
services.AddDbContext<AuditContext>(options =>
{
options.UseSqlServer(connStringAudit, b => b.MigrationsAssembly("Web.Hosting"));
if (environment.IsDevelopment())
options.EnableSensitiveDataLogging();
});
@MaklaCof Don't call AddEntityFrameworkNpgsql or AddEntityFrameworkSqlServer anywhere. These aren't methods that applications should call under normal conditions.
I also got this error
- startup config:
// Add EntityFramework support for SqlLite3.
services.AddEntityFrameworkSqlite();
// Add DatabaseDbContext.
services.AddDbContext<DatabaseDbContext>((options) =>
options.UseSqlite(Configuration.GetConnectionString("DatabaseDbContext"))
);
Error:
PM> Add-Migration InitialCreate -c DatabaseDbContext -o Data/Migrations
Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Infrastructure[10410]
'AddEntityFramework*' was called on the service provider, but 'UseInternalServiceProvider' wasn't called in the DbContext options configuration. Remove the 'AddEntityFramework*' call as in most cases it's not needed and might cause conflicts with other products and services registered in the same service provider.
To undo this action, use Remove-Migration.
MaklaCof: thank you! I remove UseInternalServiceProvider & AddEntityFrameworkSqlite
It worked
good luck 👍

What is the correct way to:
- register to enable the NetTopologySuite
- while somehow getting access to the service provider used by the DbContext
What am i trying todo:
- Using MiniProfiler + EntityFramework extension
- The profiler renders sql generated nicely to C&P into SSMS (with declared params)
- However it fails to properly render Geometry values (TopologySuite) as they are stored as byte[] in the
DbCommand(which is what we have access to from within MiniProfiler) - We already figured out how to convert the byte[] in the DbCommand to a SQL Literal
- But for that I need access the registered mapping plugins (
IRelationalTypeMappingSourcePlugin)
I see two options>
UseUseInternalServiceProvider` => However TopologySuite then throws the above exception- Or somehow access the internally used service provider
Both options are fine, would appreciate any pointers how to achieve this.