hunostor icon

.net core setup sqlite database

hunostor | PRO | 11/23/18 09:54:42 AM UTC | 0 ⭐ | 251 👁️ | Never ⏰ | []
C# |

770 B

|

None

|

0 👍

/

0 👎

// Installed Microsoft.EntityFrameworkCore.Sqlite nugets pack
// appsetting.json change connection string to sqlite
"ConnectionStrings": {
    //"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-App-E89CAB16-C51C-4FB1-8EAD-B43F5E23C63E;Trusted_Connection=True;MultipleActiveResultSets=true"
    "Sqlite": "Database.db"
  },
 
// Startup.css method ConfigureServives method
services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlite(
                    Configuration.GetConnectionString("Sqlite")));
 
// DbContext class extended class, overrice OnConfiguring method
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Filename=Database.db");
        }

Comments