一聚教程网:一个值得你收藏的教程网站

热门教程

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

时间:2022-06-25 03:38:14 编辑:袖梨 来源:一聚教程网

第一步:在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数据库例子 

 

热门栏目