问题
I'm using Entity Framework 4.2 CF with SQLite, but when i try to launch the application i got "CreateDatabase is not supported by the provider" error. This is my model mapping:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
#region NewsMapping
modelBuilder.Entity<News>().ToTable("news");
modelBuilder.Entity<News>().HasKey(x => x.Id).Property(x => x.Id).HasColumnName("ID").HasColumnOrder(0);
modelBuilder.Entity<News>().Property(x => x.Status).HasColumnName("STATUS");
modelBuilder.Entity<News>().Property(x => x.NewsTitle).HasColumnName("NEWS_TITLE");
modelBuilder.Entity<News>().Property(x => x.Content).HasColumnName("CONTENT_1");
modelBuilder.Entity<News>().Property(x => x.IsImportant).HasColumnName("IS_IMPORTANT");
modelBuilder.Entity<News>().Property(x => x.OrderNumber).HasColumnName("ORDER_NUMBER");
modelBuilder.Entity<News>().Property(x => x.CreateDate).HasColumnName("CREATE_DATE");
#endregion
base.OnModelCreating(modelBuilder);
}
What is wrong in this code?
Thanks
回答1:
Nothing is wrong in the code. The error says exactly what is going on. Your EF provider for SQLite (System.Data.SQLite
) doesn't provide database creation so you must create database and all tables manually before you launch the application.
回答2:
Ok i found the solution, the provider doesn't support "Database Creation", so i had to initialize it empty:
public EkosContext()
{
Database.SetInitializer<EkosContext>(null);
}
回答3:
I got this error for EF 6.1.3
and System.Data.Sqlite 1.0.103
because I did not specify the location of the database file properly in my web.config
file.
To fix the problem I moved the database file to App_Data
and changed my connection string to connectionString="data source=|DataDirectory|databaseName;Version=3;"
回答4:
As been because of the wrong path of my sqlitedb for me in the web.config, as simple and stupid that annoying.
来源:https://stackoverflow.com/questions/8505999/sqlite-createdatabase-not-supported-error