EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Document the internal/external service provider separation

Open nikkhoo63 opened this issue 6 years ago • 7 comments
trafficstars

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

nikkhoo63 avatar Mar 19 '19 09:03 nikkhoo63

@nikkhoo63 - This seems like a product issue. Can you provide repro solution/steps?

smitpatel avatar Apr 10 '19 01:04 smitpatel

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.

Hilqueslei avatar Jan 18 '20 12:01 Hilqueslei

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 avatar Apr 17 '20 08:04 MaklaCof

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

ajcvickers avatar Apr 17 '20 15:04 ajcvickers

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.

ngnam avatar Apr 27 '20 03:04 ngnam

MaklaCof: thank you! I remove UseInternalServiceProvider & AddEntityFrameworkSqlite

image It worked good luck 👍 image

ngnam avatar Apr 27 '20 04:04 ngnam

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>

  • Use UseInternalServiceProvider` => 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.

ntziolis avatar May 31 '20 10:05 ntziolis