gpt4 book ai didi

c# - SQLite 与 Entity Framework

转载 作者:太空宇宙 更新时间:2023-11-03 15:51:18 31 4
gpt4 key购买 nike

<分区>

我无法配置 App.config。我有错误

  • base {"Unable to determine the provider name for provider factory of type 'System.Data.SQLite.SQLiteFactory'. Make sure that the ADO.NET provider is installed or registered in the application config."} 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; }
}

和 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 添加到项目中,EF 和 SQLite 由 nuget 添加

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com