我正在尝试实现基于EF(6.1.3)和SQLite的数据服务。我在一个非常小的测试应用程序中工作,但无法看到复制这种体验。我的数据服务类库已加载system.data.sqlite ....组件。我还加载了SQLite.CodeFirst,因为我读到EF 6.1.3中的创建函数对于SQLite来说并不完整。 但是,调用数据服务时得到的错误是:
System.InvalidOperationException occurred HResult=0x80131509 Message=No Entity Framework
provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'.
Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
我认为这必须在app.config文件中,但似乎无法找出配置的错误。
以下是上下文类的代码。
public class IRMContext : DbContext
{
public DbSet<Operator> Operators { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var sqlLiteInit = new SqliteDropCreateDatabaseWhenModelChanges<IRMContext>(modelBuilder);
Database.SetInitializer<IRMContext>(sqlLiteInit);
}
}
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"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.0.96.0" newVersion="1.0.96.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="IRMContext" connectionString="Data Source=C:\IRManager\IRManager.sqlite" providerName="System.Data.SQLite"/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.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"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<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>
任何帮助/指针将不胜感激。感谢
答案 0 :(得分:2)
我将我的问题追溯到两个问题。
我的主要问题似乎是我使用SQLite的大部分经验都是在UWP应用程序中,但事实并非如此。
感谢。