Reputation: 2347
I am trying to run a demo app to do a POC on Linq-to-Sqlite. I'm using the latest System.Data.Sqlite NuGet package and .Net Framework 4.5 to create sample console application which will only create the database file initially. The code simply creates an object of Movie class and adds it to the DbSet property on the DbContext class. However, on SaveChanges(), i get a System.Data.Entity.Infrastructure.DbUpdateException with the message "no such table: Movie". Below is my code:
if (!File.Exists(_databaseFilePath))
SQLiteConnection.CreateFile(_databaseFilePath);
using (var dbContext = new MovieAppContext())
{
dbContext.Movies.Add(new Movie(1, "Titanic", 7.5));
var retVal = dbContext.SaveChanges();
}
public class MovieAppContext : DbContext
{
public MovieAppContext():base("MovieAppConStr")
{
}
public MovieAppContext(string connectionString)
: base(connectionString)
{ }
public DbSet<Movie> Movies { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Chinook Database does not pluralize table names
modelBuilder.Conventions
.Remove<PluralizingTableNameConvention>();
}
}
EDIT: So the question is, just like Linq-to-Sql, does Linq-to-Sqlite provider allow us to create tables in the database equivalent to the models created using the code-first approach ?
Upvotes: 0
Views: 439
Reputation: 41809
Entity Framework Code First with SQLite only Works with an existing database, so no. There are alternative EF providers for sqlite that do support database creation with Code First... Devart for example
Upvotes: 0