我按照本教程启动了一个将Entity Framework 5与SQLite数据库一起使用的项目:http://brice-lambson.blogspot.be/2012/10/entity-framework-on-sqlite.html
但是,在我的应用程序中,我有多个项目:
现在我遇到以下异常:
System.NotSupportedException未处理HResult = -2146233067
Message =无法确定连接类型的提供程序名称 'System.Data.SqlClient.SqlConnection'。源=的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 :(得分: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" />
答案 1 :(得分: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>