Entity Framework 7 And SQLite Tables Not Creating
Solution 1:
Check out Getting Started on UWP - EF 7 in the official docs. The following notes are from that document.
The default path on UWP is not writable. Your DB file needs to be in ApplicationData.Current.LocalFolder
options.UseSqlite("Data Source=" + Path.Combine(ApplicationData.Current.LocalFolder.Path, "blogging.db"))
Also, take note that on UWP you cannot run migrations from commands. You need to run them in the app.
using (var db = new BloggingContext())
{
db.Database.Migrate();
}
Solution 2:
The DbContext class contains configuration of your database - tables, relationsships, etc. To use the DbContext you need to create a database that matches your DbContext. In the Code-first world, it is done by database migrations.
For ASP.NET 5 you need to add this configuration to your project.json file
"commands": {
"ef": "EntityFramework.Commands"
}
and then add a migration to your project and apply this migration to the DB by running following commands
dnx ef migrations add MyFirstMigration
dnx ef database update
For Full .NET you need to run following commands in the Package Manager Console (Tools ‣ NuGet Package Manager ‣ Package Manager Console)
Install-Package EntityFramework.Commands –Pre
Add-Migration MyFirstMigration
Update-Database
Post a Comment for "Entity Framework 7 And SQLite Tables Not Creating"