2023-07-19 19:51:39 +08:00
|
|
|
|
using OrmTest;
|
|
|
|
|
using SqlSugar;
|
2024-05-09 11:17:52 +08:00
|
|
|
|
using SqlSugar.OceanBaseForOracle;
|
2024-05-11 10:54:01 +08:00
|
|
|
|
using static Npgsql.Replication.PgOutput.Messages.RelationMessage;
|
2023-07-19 19:51:39 +08:00
|
|
|
|
|
|
|
|
|
namespace OceanBaseForOracle
|
|
|
|
|
{
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("#### MasterSlave Start ####");
|
2024-05-09 11:17:52 +08:00
|
|
|
|
|
|
|
|
|
//程序启动时加上只要执行一次
|
|
|
|
|
InstanceFactory.CustomAssemblies =
|
|
|
|
|
new System.Reflection.Assembly[] { typeof(OceanBaseForOracleProvider).Assembly };
|
|
|
|
|
|
|
|
|
|
|
2023-07-19 23:49:55 +08:00
|
|
|
|
//OceanBase Oracle 模式用这个 DbType.OceanBaseForOracle
|
|
|
|
|
//OceanBase MySql 模式用DbType.MySql不要用这个
|
2023-07-19 19:51:39 +08:00
|
|
|
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
|
ConnectionString = Config.ConnectionString,//Master Connection
|
2023-07-19 23:49:55 +08:00
|
|
|
|
DbType = DbType.OceanBaseForOracle,//Oracle 模式用这个 ,如果是MySql 模式用DbType.MySql
|
2023-07-19 19:51:39 +08:00
|
|
|
|
InitKeyType = InitKeyType.Attribute,
|
|
|
|
|
IsAutoCloseConnection = true
|
|
|
|
|
});
|
|
|
|
|
db.Aop.OnLogExecuted = (s, p) =>
|
|
|
|
|
{
|
2024-05-18 14:26:33 +08:00
|
|
|
|
Console.WriteLine(s);
|
2023-07-19 19:51:39 +08:00
|
|
|
|
};
|
2024-05-18 14:26:33 +08:00
|
|
|
|
|
|
|
|
|
Console.WriteLine(db.Ado.IsValidConnection());
|
|
|
|
|
if (db.DbMaintenance.IsAnyTable("OrderTest", false))
|
|
|
|
|
{
|
|
|
|
|
//创建表
|
|
|
|
|
db.DbMaintenance.DropTable<OrderTest>();
|
|
|
|
|
//测试修改表
|
|
|
|
|
db.CodeFirst.InitTables<OrderTest>();
|
|
|
|
|
db.CodeFirst.InitTables<OrderTest>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.Insertable(new OrderTest() { Id = 109, Name = "abc", CustomId = 1, CreateTime = DateTime.Now })
|
|
|
|
|
.ExecuteReturnSnowflakeId();
|
|
|
|
|
|
|
|
|
|
db.Deleteable<OrderTest>().Where(m => m.Id == 109).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
db.Updateable<OrderTest>().SetColumns(m => new OrderTest
|
2024-05-11 10:13:19 +08:00
|
|
|
|
{
|
2024-05-11 10:54:01 +08:00
|
|
|
|
Name = "我是修改"
|
|
|
|
|
}).Where(m => m.Id == 2).ExecuteCommand();
|
2024-05-18 14:26:33 +08:00
|
|
|
|
|
|
|
|
|
var pageList = db.Queryable<OrderTest>().OrderBy(m => m.Id).ToOffsetPage(1, 3);
|
2023-07-19 19:51:39 +08:00
|
|
|
|
Console.WriteLine("#### MasterSlave End ####");
|
|
|
|
|
}
|
2024-05-18 14:26:33 +08:00
|
|
|
|
|
|
|
|
|
|
2023-07-19 19:51:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|