C# 具有实体框架的SQLite
我无法配置App.config。我有错误C# 具有实体框架的SQLite,c#,entity-framework,sqlite,C#,Entity Framework,Sqlite,我无法配置App.config。我有错误 base{“无法确定类型为“System.Data.SQLite.SQLiteFactory”的提供程序工厂的提供程序名称。请确保已在应用程序配置中安装或注册ADO.NET提供程序。“}System.SystemException{System.NotSupportedException} 我的代码: class Program { static void Main(string[] args) { new Progr
- base{“无法确定类型为“System.Data.SQLite.SQLiteFactory”的提供程序工厂的提供程序名称。请确保已在应用程序配置中安装或注册ADO.NET提供程序。“}System.SystemException{System.NotSupportedException}
class Program
{
static void Main(string[] args)
{
new Program();
}
public Program()
{
CustomerContext cc = new CustomerContext();
cc.Customers.Add(new Customer() { Name = "sdf", LastName = "dfs" });
}
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
}
public class CustomerContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
类程序
{
静态void Main(字符串[]参数)
{
新程序();
}
公共计划()
{
CustomerContext cc=新建CustomerContext();
cc.Customers.Add(新客户(){Name=“sdf”,LastName=“dfs”});
}
}
公共类客户
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串LastName{get;set;}
}
公共类CustomerContext:DbContext
{
公共数据库集客户{get;set;}
}
和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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<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>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<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" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="CustomerContext" connectionString="Data Source=test.sqlite" providerName="System.Data.SQLite.EF6" />
</connectionStrings>
</configuration>
文件test.sqlite添加到项目中,nuget也添加了EF和sqlite,注释如下:
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
另外,实体框架(edmx文件)是在应用程序项目中定义的还是在单独的类库中定义的
如果它位于单独的类库中,则将类库项目的应用程序配置文件中的xml复制到应用程序项目的应用程序配置文件中
更新:
上次我检查时,SQLite必须在应用程序项目中定义,而不是单独的类库。实体框架位于单独的库中,但我没有任何edmx文件。您是否已将实体框架添加到项目中?如果是,您是否创建了实体?另外,请参阅我发布的答案的更新。所有内容都在我的应用程序项目中,数据库已创建,但仍然无法工作。您确定您的应用程序项目中引用了SQLite吗?您的SQLite版本是否与作为提供商的EF版本兼容?为什么要将SQLite与EF一起使用?是的,我添加了nuget atomaticaly的所有内容。Sqlite版本1.0.93.0可能是我的答案这里有帮助(观看视频):@TomL我正在做视频中的所有事情,但当我单击工具->连接到数据库时,我在数据源中没有Sqlite您使用的是哪个版本的Visual Studio?解释和视频是针对VS 2013专业版的。Express Edition可能不起作用,2012年,您可能需要下载sqlite-netFx45-setup-bundle-x86-2012-1.0.93.0.exe并以4.5 framework.2013 Express为目标,但我已经通过使用VS2010解决了这一问题,并且在没有您的“魔力”的情况下,它可以正常工作,只需由nuget安装所有内容即可。“魔力”显然不适用于Express Edition,但很好,你让它工作了。我希望一个新的System.Data.SQLite更新可以改善情况。。。