Ma solution a 3 projets:Migration Comment passer la chaîne de connexion dans le Projet Bibliothèque (.netStandard)
- entité (y compris Dbcontext, ...), le cadre cible .NetStandard 1.4, bibliothèque type de projet
- WebAPI
webui
Je veux créer la fonction migrer dans l'entité projet. Dans projet Entité, j'ai une classe ApplicationContextFactory
public class ApplicationContextFactory : IDbContextFactory<ApplicationContext> { public ApplicationContext Create(DbContextFactoryOptions options) { var optionsBuilder = new DbContextOptionsBuilder<ApplicationContext>(); return new ApplicationContext(optionsBuilder.Options); } }
Je veux passer la chaîne de connexion de WebAPI au projet Entité Mon StartUp classe (WebAPI)
services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnection")));
mais quand j'utiliser la commande Ajouter -Migration InitialMigration puis je me suis une erreur:
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.
Bonjour, pouvez-vous révéler votre classe DbContext? Il semble que vous n'utilisiez pas correctement le modèle d'options. –