0

Meine Lösung hat 3 Projekte weitergeben müssen:Migration Wie Connection String in Library Project (.netStandard)

  • Entity (einschließlich DbContext, ...), Zielframework .NetStandard 1.4, Projekttypbibliothek
  • WebAPI
  • WebUI

  • ich möchte Funktion in Entity-Projekt migrieren erstellen. In Entity-Projekt habe ich eine Klasse ApplicationContextFactory

    public class ApplicationContextFactory : IDbContextFactory<ApplicationContext> 
    { 
        public ApplicationContext Create(DbContextFactoryOptions options) 
        { 
         var optionsBuilder = new DbContextOptionsBuilder<ApplicationContext>(); 
         return new ApplicationContext(optionsBuilder.Options); 
        } 
    } 
    

ich aus WebAPI Strangverschaltung wollen Projekt Entity passieren Mein StartUp-Klasse (WebAPI)

services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnection"))); 

aber wenn ich Befehl hinzufügen -Migration InitialMigration dann habe ich einen Fehler:

No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext. 
+0

Hallo, können Sie Ihre DbContext-Klasse offenbaren? Es scheint, dass Sie das Optionsmodell nicht ordnungsgemäß verwenden. –

Antwort

2

Ich löste dieses iss Ue. weil in meiner Lösung, die 2 Projekte WebUI und WebAPI hat, ich nur als Startprojekt von WebAPI gesetzt, die die Verbindungszeichenfolge enthält und es funktioniert gut

Verwandte Themen