2025-03-31 08:03:24 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
|
|
|
|
|
2025-04-01 12:50:11 +08:00
|
|
|
|
//说明:GaussDB原生驱动访问数据库
|
|
|
|
|
|
|
|
|
|
//这行代码扔程序启动时
|
|
|
|
|
InstanceFactory.CustomAssemblies = new System.Reflection.Assembly[] {
|
|
|
|
|
typeof(SqlSugar.GaussDBCore.GaussDBDataAdapter).Assembly };
|
|
|
|
|
|
2025-03-31 08:03:24 +08:00
|
|
|
|
//创建DB
|
|
|
|
|
var db = new SqlSugarClient(new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
|
ConnectionString = "PORT=5432;DATABASE=SqlSugar5Demo;HOST=localhost;PASSWORD=postgres;USER ID=postgres",
|
2025-04-01 12:50:11 +08:00
|
|
|
|
DbType = SqlSugar.DbType.GaussDBNative,
|
2025-03-31 08:03:24 +08:00
|
|
|
|
IsAutoCloseConnection = true,
|
|
|
|
|
MoreSettings = new ConnMoreSettings()
|
|
|
|
|
{
|
|
|
|
|
DatabaseModel = SqlSugar.DbType.OpenGauss
|
|
|
|
|
}
|
|
|
|
|
}, db =>
|
2025-04-01 12:50:11 +08:00
|
|
|
|
{
|
2025-03-31 08:03:24 +08:00
|
|
|
|
db.Aop.OnLogExecuting = (x, y) =>
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(x);
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-01 12:50:11 +08:00
|
|
|
|
});
|
2025-03-31 08:03:24 +08:00
|
|
|
|
|
|
|
|
|
db.Open();
|
|
|
|
|
db.Close();
|
|
|
|
|
|
|
|
|
|
var dt = db.Ado.GetDataTable("SELECT * from tb_user limit 10");
|
|
|
|
|
|
|
|
|
|
dt.AsEnumerable().ToList().ForEach(r =>
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(r[0].ToString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Hello, World!");
|