hunostor

.net core setup sqlite database

Nov 23rd, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. // Installed Microsoft.EntityFrameworkCore.Sqlite nugets pack
  2. // appsetting.json change connection string to sqlite
  3. "ConnectionStrings": {
  4.     //"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-App-E89CAB16-C51C-4FB1-8EAD-B43F5E23C63E;Trusted_Connection=True;MultipleActiveResultSets=true"
  5.     "Sqlite": "Database.db"
  6.   },
  7.  
  8. // Startup.css method ConfigureServives method
  9. services.AddDbContext<ApplicationDbContext>(options =>
  10.                 options.UseSqlite(
  11.                     Configuration.GetConnectionString("Sqlite")));
  12.  
  13. // DbContext class extended class, overrice OnConfiguring method
  14. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  15.         {
  16.             optionsBuilder.UseSqlite("Filename=Database.db");
  17.         }
Add Comment
Please, Sign In to add comment