asp.net EntityFramework 6连接Sqlite数据库例子

作者:袖梨 2022-06-25

第一步:在NuGet安装System.Data.Sqlite程序包

asp.net EntityFramework 6连接Sqlite数据库例子

第二步:生成实体类

我试了很多次,尝试用Entity Framework Power Tools Beta 4连接Sqlite生成实体类,但都失败了,最后的解决办法是在SQL Server创建一个相同结构的库,EF Power Tools连接SQL Server生成实体类,生成完后记得修改配置文件中数据库连接字符串:


注意:EntityFramework 6连接Sqlite数据库提供程序不是System.Data.SQLite,得用System.Data.SQLite.EF6,这在配置文件(App.config)中有解释说明。

第三步:最终App.config内容如下

引用内容







providerName="System.Data.SQLite.EF6" />





















第四步:测试程序


using(testContext context = new testContext())
{
List people = context.People.ToList();
foreach(Person item in people)
{
Console.WriteLine("{0},{1}", item.Name, item.Age);
}
}

asp.net EntityFramework 6连接Sqlite数据库例子

相关文章

精彩推荐