如何从 SqlKata 连接到 postgras 数据库?
How to connect from SqlKata to postgras database?
我在 visual studio 中使用 dot net core 并使用 Npgsql 连接到 postgras sql 现在我想使用 sql 查询数据库kata 但我无法连接到我的 postgras 数据库,任何人都可以帮助我吗?我安装它并按照基于此 link enter link description here 的说明进行操作,但它不连接并抛出异常 "A network-related or instance-specific error occurred while establishing a connection to SQL Server..."
尝试这样的事情
using SqlKata;
using SqlKata.Compilers;
using SqlKata.Execution;
using Npgsql;
// Setup the connection and compiler
var connection = new NpgsqlConnection(Host=localhost;Username=yourUserName;Password=yourPassword;Database=postgres";);
var compiler = new PostgresCompiler();
var db = new QueryFactory(connection, compiler);
// You can register the QueryFactory in the IoC container
var user = db.Query("Users").Where("Id", 1).Where("Status", "Active").First();
您应该创建自定义 PostgresCompiler
var connection = new NpgsqlConnection("Host=localhost;Username=username;Password=pass;Database=db name");
connection.Open();
var compiler2 = new MyPostgresCompiler();
var db2 = new QueryFactory(connection, compiler2);
var list = new XQuery(connection, compiler2).From("employee").Get();
MyPostgresCompiler 是:
`public class MyPostgresCompiler : PostgresCompiler{
public MyPostgresCompiler()
{
OpeningIdentifier = string.Empty;
ClosingIdentifier = string.Empty;
}
public override string WrapValue(string value)
{
return value;
}}`
我在 visual studio 中使用 dot net core 并使用 Npgsql 连接到 postgras sql 现在我想使用 sql 查询数据库kata 但我无法连接到我的 postgras 数据库,任何人都可以帮助我吗?我安装它并按照基于此 link enter link description here 的说明进行操作,但它不连接并抛出异常 "A network-related or instance-specific error occurred while establishing a connection to SQL Server..."
尝试这样的事情
using SqlKata;
using SqlKata.Compilers;
using SqlKata.Execution;
using Npgsql;
// Setup the connection and compiler
var connection = new NpgsqlConnection(Host=localhost;Username=yourUserName;Password=yourPassword;Database=postgres";);
var compiler = new PostgresCompiler();
var db = new QueryFactory(connection, compiler);
// You can register the QueryFactory in the IoC container
var user = db.Query("Users").Where("Id", 1).Where("Status", "Active").First();
您应该创建自定义 PostgresCompiler
var connection = new NpgsqlConnection("Host=localhost;Username=username;Password=pass;Database=db name");
connection.Open();
var compiler2 = new MyPostgresCompiler();
var db2 = new QueryFactory(connection, compiler2);
var list = new XQuery(connection, compiler2).From("employee").Get();
MyPostgresCompiler 是:
`public class MyPostgresCompiler : PostgresCompiler{
public MyPostgresCompiler()
{
OpeningIdentifier = string.Empty;
ClosingIdentifier = string.Empty;
}
public override string WrapValue(string value)
{
return value;
}}`