前言:因使用sqlite时发现,根据 EntityFramework创建ADO.NET实体类数据库时并未找到sqlite(本身是没有sqlite驱动的,只有sql server,oracle等数据库),所以才有了下面这些操作
步骤1、从网址https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki下载
双击进行安装
步骤2:从Nuget程序包管理器中下载相关包
步骤3:配置App.config文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<!--添加ADO.NET时自动生成(此步骤不需要配置这条),注意别忘了选择数据库文件-->
<add name="数据库文件名称Entities" connectionString="metadata=res://*/db.MonitoringWarning.csdl|res://*/db.MonitoringWarning.ssdl|res://*/db.MonitoringWarning.msl;provider=System.Data.SQLite.EF6;provider connection string='data source="数据库文件所在路径\MonitoringWarning.db"'" providerName="System.Data.EntityClient" /></connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<!--添加下面这句,不然可能报错-->
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<system.data>
<DbProviderFactories>
<!--add标签是一定要在remove标签之后的-->
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
</system.data></configuration>
步骤4:创建ADO.NET实体类数据库
往下进行就行,相信用过的都会