ExampleDbContextFactory.cs 985 B

123456789101112131415161718192021222324252627
  1. using System.Diagnostics;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Design;
  4. using Microsoft.Extensions.Configuration;
  5. using VCommonCoreExample.Configuration;
  6. namespace VCommonCoreExample.EntityFrameworkCore
  7. {
  8. /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
  9. public class ExampleDbContextFactory : IDesignTimeDbContextFactory<ExampleDbContext>
  10. {
  11. public ExampleDbContext CreateDbContext(string[] args)
  12. {
  13. Debugger.Launch();
  14. Debugger.Break();
  15. var builder = new DbContextOptionsBuilder<ExampleDbContext>();
  16. var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());
  17. ExampleDbContextConfig.Configure(builder, configuration.GetConnectionString(ProjectConst.ConnectionStringName));
  18. return new ExampleDbContext(builder.Options);
  19. }
  20. }
  21. }