2013-09-22 37 views
1

我跟着本教程开始使用实体框架5与一个SQLite数据库项目:http://brice-lambson.blogspot.be/2012/10/entity-framework-on-sqlite.html实体框架SQLite数据库:NotSupportedException异常

然而,在我的申请,我中有多个项目:

  • 项目.UI:前端逻辑
  • Project.Model:所述POCO类
  • Project.DataAccess:数据访问逻辑:实体框架项目

现在我得到以下异常:

System.NotSupportedException了未处理的HResult = -2146233067
消息=无法确定供应商名称 型“System.Data.SqlClient的连接。 SqlConnection的”。 Source = EntityFramework

我设置了教程中的所有内容,我在所有项目中安装了EF5和System.Data.SQLite。这是我从主项目的App.config:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.data> 
    <DbProviderFactories> 
     <add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /> 
    </DbProviderFactories> 
    <connectionStrings> 
     <add name="EasyInvoiceContext" connectionString="Data Source=|DataDirectory|EasyInvoice_v1.sqlite" providerName="System.Data.SQLite" /> 
    </connectionStrings> 
    </system.data> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="v11.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    </entityFramework> 
</configuration> 

有没有人知道我在做什么错?我的项目

更多的源代码可以在GitHub上找到:https://github.com/SanderDeclerck/EasyInvoice

回答

0

我发现解决方案,在App.config连接字符串应该是一个孩子的配置,而不是一个孩子的system.data。

这里的固定的App.config(测试和工作):

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.data> 
    <DbProviderFactories> 
     <add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /> 
    </DbProviderFactories> 
    </system.data> 
    <connectionStrings> 
    <add name="EasyInvoiceContext" connectionString="Data Source=|DataDirectory|Database/EasyInvoice_v1.sqlite" providerName="System.Data.SQLite" /> 
    </connectionStrings> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="v11.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    </entityFramework> 
</configuration> 
1

尝试使用完整的合格程序集名称,而在配置增加DBProviderFactory ..这样的事情。

<add name="SQLite Data Provider" 
    invariant="System.Data.SQLite" 
    description=".Net Framework Data Provider for SQLite" 
    type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /> 
+0

谢谢,但我在哪里可以找到的公钥SQLite的? –

+0

[This](http://blogs.msdn.com/b/wriju/archive/2008/07/01/how-to-find-public-key-token-for-a-net-dll-or-assembly .aspx)告诉你如何得到它。 –

+0

我试过了,但我仍然得到相同的错误,奇怪的是错误是关于“System.Data.SqlClient.SqlConnection”,而我正在使用SQLite ... –