Advertisement
otkalce

Entity Framework - configuration

Mar 28th, 2023 (edited)
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.98 KB | Source Code | 0 0
  1. // *** EF connection string configuration ***
  2. {
  3.   "Logging": {
  4.     "LogLevel": {
  5.       "Default": "Information",
  6.       "Microsoft.AspNetCore": "Warning"
  7.     }
  8.   },
  9.   "AllowedHosts": "*",
  10.   "ConnectionStrings": {
  11.     "Task06ConnStr": "server=.;Database=Task06;Trusted_Connection=True;TrustServerCertificate=True;MultipleActiveResultSets=true"
  12.   }
  13. }
  14.  
  15. // *** EF connection string configuration usage (Task06Context.cs) ***
  16. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  17.     //=> optionsBuilder.UseSqlServer(_configuration.GetConnectionString("Task06ConnStr"));
  18.     => optionsBuilder.UseSqlServer("Name=ConnectionStrings:Task06ConnStr");
  19.  
  20.  
  21. // *** EF connection string configuration usage - DI container registration (Program.cs) ***
  22. builder.Services.AddDbContext<Task06Context>(options =>
  23. {
  24.     //options.UseSqlServer(builder.Configuration.GetConnectionString("Task06ConnStr"));
  25.     options.UseSqlServer("name=ConnectionStrings:Task06ConnStr");
  26. });
  27.  
Tags: ef-usage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement