[英]Npgsql C# problem with App.Config PostgreSQL Entity Framework 6
Just made new Console App for test database. 刚为测试数据库制作了新的Console App。 It was working fine every time in my projects in past, but now i have problem which i can't solve.
过去每次在我的项目中工作都很好,但现在我遇到了无法解决的问题。 I created App.config manualy (VStudio didn't generate it).
我创建了App.config manualy(VStudio没有生成它)。 I used settings from This link .
我使用了此链接中的设置。 In past i was working with MSSql, and SQLite and it works fine.
在过去我正在使用MSSql和SQLite,它工作正常。 But my try with Postgresql not working.
但我尝试使用Postgresql无法正常工作。 Can you tell me what should i do?
你能告诉我该怎么办?
My App.config file: 我的App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- ... -->
<entityFramework>
<providers>
<provider invariantName="Npgsql"
type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql"
support="FF" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="AppDatabaseConnectionString"
connectionString="Server=localhost;Database=photo_service;Port=5432;Password=postgres;User Id=postgres"
providerName="Npgsql" />
</connectionStrings>
</configuration>
My AppDatabase:Context and class User 我的AppDatabase:上下文和类用户
class AppDatabase : DbContext
{
private readonly string schema;
public AppDatabase(string schema) : base("AppDatabaseConnectionString")
{
this.schema = schema;
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder builder)
{
builder.HasDefaultSchema(this.schema);
base.OnModelCreating(builder);
}
}
class User
{
public int id { get; set; }
public string name { get; set; }
public string number { get; set; }
}
And finally my initialization of postgres query: 最后我的postgres查询初始化:
var db = new AppDatabase("Users");
using (var database = new AppDatabase("User"))
{
var users = database.Users.First(user => user.name == "Blah blah blah");
}
it all gives me error: 这一切都给了我错误:
Unable to determine the provider name for provider factory of type
'System.Data.SqlClient.SqlClientFactory'. Make sure that the ADO.NET provider is
installed or registered in the application config.'
Okay, solved. 好的,解决了。 I created
ConsoleApp .NET Framework
instead ConsoleApp .NET Core
as github says github说,我创建了
ConsoleApp .NET Framework
而不是ConsoleApp .NET Core
EF6 does not (yet) run on .NET Core--see
EF6(尚未)在.NET Core上运行 - 请参阅
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.