Entityframework.docs: Document the internal/external service provider separation

Created on 19 Mar 2019  路  7Comments  路  Source: dotnet/EntityFramework.Docs

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:
Untitled10

area-context-management

Most helpful comment

@MaklaCof Don't call AddEntityFrameworkNpgsql or AddEntityFrameworkSqlServer anywhere. These aren't methods that applications should call under normal conditions.

All 7 comments

@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

image

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

image
It worked
good luck 馃憤
image

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

speciesunknown picture speciesunknown  路  3Comments

VirMaker picture VirMaker  路  4Comments

MohammadMQ picture MohammadMQ  路  3Comments

SychevIgor picture SychevIgor  路  4Comments

weitzhandler picture weitzhandler  路  4Comments