【发布时间】:2019-01-09 22:38:32
【问题描述】:
我尝试使用 SQLite 为实体框架运行 CodeFirst 示例。 NuGet 包 SQLite.CodeFirst 已安装并运行无错误 但它不会创建 SQLite 数据库。 这是我的代码:
using SQLite.CodeFirst;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Text;
namespace EF6SqliteExample
{
class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
class MyContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
var model = modelBuilder.Build(Database.Connection);
ISqlGenerator sqlGenerator = new SqliteSqlGenerator();
string sql = sqlGenerator.Generate(model.StoreModel);
}
public DbSet<Person> Persons { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (var db = new MyContext())
{
var person = new Person() { Name = "John" };
db.Persons.Add(person);
db.SaveChanges();
}
}
}
}
连接字符串是:
<connectionStrings>
<add name="MyDB" connectionString="data source=.\MyDB.sqlite" providerName="System.Data.SQLite" />
</connectionStrings>
【问题讨论】:
标签: c# sqlite entity-framework-6 ef-code-first