Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public static class DbOptionsFactory
  2. {
  3. static DbOptionsFactory()
  4. {
  5. var config = new ConfigurationBuilder()
  6. .AddJsonFile("appsettings.json")
  7. .Build();
  8. var connectionString = config["Data:DefaultConnection:ConnectionString"];
  9.  
  10. DbContextOptions = new DbContextOptionsBuilder<MyDbContext>()
  11. .UseSqlServer(connectionString)
  12. .Options;
  13. }
  14.  
  15. public static DbContextOptions<MyDbContext> DbContextOptions { get; }
  16.  
  17. }
  18.  
  19. {
  20. "Data": {
  21. "DefaultConnection": {
  22. "Name": "MyDbContext",
  23. "ConnectionString": "connection string goes here"
  24. }
  25. }
  26. }
  27.  
  28. using (var context = new JmsDbContext(DbOptionsFactory.DbContextOptions))
  29. {
  30. // access db here
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement