diff --git a/Src/Asp.Net/OracleTest/Demo/Demo0_SqlSugarClient.cs b/Src/Asp.Net/OracleTest/Demo/Demo0_SqlSugarClient.cs index 3b66869af..c8ff54bc5 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo0_SqlSugarClient.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo0_SqlSugarClient.cs @@ -17,7 +17,6 @@ namespace OrmTest SqlSugarClient();//Create db DbContext();//Optimizing SqlSugarClient usage SingletonPattern();//Singleten Pattern - DistributedTransactionExample(); MasterSlave();//Read-write separation CustomAttribute(); } @@ -29,7 +28,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString,//Master Connection - DbType = DbType.SqlServer, + DbType = DbType.Oracle, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, SlaveConnectionConfigs = new List() { @@ -37,6 +36,7 @@ namespace OrmTest new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } } }); + db.Aop.OnLogExecuted = (s, p) => { Console.WriteLine(db.Ado.Connection.ConnectionString); @@ -54,7 +54,7 @@ namespace OrmTest Console.WriteLine("#### SqlSugarClient Start ####"); SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, @@ -68,11 +68,17 @@ namespace OrmTest } }); - //If no exist create datebase - db.DbMaintenance.CreateDatabase(); + + var isAnySeq = db.Ado.GetInt("SELECT COUNT(*) FROM USER_SEQUENCES WHERE SEQUENCE_NAME = 'SEQ_ID'") >0; + //Create seq 相当于创建一个自增标识 + if (!isAnySeq) + { + db.Ado.ExecuteCommand("CREATE SEQUENCE Seq_Id"); + } + //Use db query - var dt = db.Ado.GetDataTable("select 1"); + var dt = db.Ado.GetDataTable("select 1 from dual"); //Create tables db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order)); @@ -147,7 +153,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, - DbType = DbType.SqlServer, + DbType = DbType.Oracle, IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute, ConfigureExternalServices = new ConfigureExternalServices() @@ -210,7 +216,7 @@ namespace OrmTest new ConnectionConfig() { ConfigId = 1, - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, @@ -219,126 +225,6 @@ namespace OrmTest OnLogExecuting = (sql, p) => { Console.WriteLine(sql); } } }); - - - private static void DistributedTransactionExample() - { - Console.WriteLine(""); - Console.WriteLine("#### Distributed TransactionExample Start ####"); - SqlSugarClient db = new SqlSugarClient(new List() - { - new ConnectionConfig(){ ConfigId="1", DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString,InitKeyType=InitKeyType.Attribute,IsAutoCloseConnection=true }, - new ConnectionConfig(){ ConfigId="2", DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString2 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true} - }); - - //use db1 - db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));// - db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand(); - Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable().Count()); - - //use db2 - db.ChangeDatabase("2"); - db.DbMaintenance.CreateDatabase();//Create Database2 - db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem)); - db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand(); - Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable().Count()); - - // Example 1 - Console.WriteLine("Example 1"); - try - { - db.BeginTran(); - - db.ChangeDatabase("1");//use db1 - db.Deleteable().ExecuteCommand(); - Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - - db.ChangeDatabase("2");//use db2 - db.Deleteable().ExecuteCommand(); - Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - - throw new Exception(); - db.CommitTran(); - } - catch - { - db.RollbackTran(); - Console.WriteLine("---Roll back"); - db.ChangeDatabase("1");//use db1 - Console.WriteLine(db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - - db.ChangeDatabase("2");//use db2 - Console.WriteLine(db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - } - - - - // Example 2 - Console.WriteLine("Example 2"); - - var result=db.UseTran(() => - { - - db.ChangeDatabase("1");//use db1 - db.Deleteable().ExecuteCommand(); - Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - - db.ChangeDatabase("2");//use db2 - db.Deleteable().ExecuteCommand(); - Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - throw new Exception(""); - - }); - if (result.IsSuccess == false) { - Console.WriteLine("---Roll back"); - db.ChangeDatabase("1");//use db1 - Console.WriteLine(db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - - db.ChangeDatabase("2");//use db2 - Console.WriteLine(db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - } - - // Example 3 - Console.WriteLine("Example 3"); - - var result2 = db.UseTranAsync(() => - { - - db.ChangeDatabase("1");//use db1 - db.Deleteable().ExecuteCommand(); - Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - - db.ChangeDatabase("2");//use db2 - db.Deleteable().ExecuteCommand(); - Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - throw new Exception(""); - - }); - result2.Wait(); - if (result.IsSuccess == false) - { - Console.WriteLine("---Roll back"); - db.ChangeDatabase("1");//use sqlserver - Console.WriteLine(db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - - db.ChangeDatabase("2");//use mysql - Console.WriteLine(db.CurrentConnectionConfig.DbType); - Console.WriteLine(db.Queryable().Count()); - } - - Console.WriteLine("#### Distributed TransactionExample End ####"); - } } /// @@ -353,7 +239,7 @@ namespace OrmTest Db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, - DbType = DbType.SqlServer, + DbType = DbType.Oracle, IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute, AopEvents = new AopEvents() @@ -387,7 +273,7 @@ namespace OrmTest Db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, - DbType = DbType.SqlServer, + DbType = DbType.Oracle, IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute, AopEvents = new AopEvents() diff --git a/Src/Asp.Net/OracleTest/Demo/Demo1_Queryable.cs b/Src/Asp.Net/OracleTest/Demo/Demo1_Queryable.cs index fa82db4e7..6a02e2550 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo1_Queryable.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo1_Queryable.cs @@ -171,7 +171,7 @@ namespace OrmTest .Mapper(it => it.B, it => it.BId).ToList(); //Manual mode - var result = db.Queryable().Take(10).Select().Mapper((itemModel, cache) => + var result = db.Queryable().Select().Mapper((itemModel, cache) => { var allItems = cache.Get(orderList => { var allIds = orderList.Select(it => it.Id).ToList(); @@ -189,7 +189,7 @@ namespace OrmTest Console.WriteLine("#### No Entity Start ####"); var db = GetInstance(); - var list = db.Queryable().AS("order ").Where("id=id", new { id = 1 }).ToList(); + var list = db.Queryable().AS("order").Where("id=id", new { id = 1 }).ToList(); var list2 = db.Queryable("o").AS("order").AddJoinInfo("OrderDetail", "i", "o.id=i.OrderId").Where("id=id", new { id = 1 }).Select("o.*").ToList(); Console.WriteLine("#### No Entity End ####"); @@ -252,7 +252,7 @@ namespace OrmTest //id=@id var list4 = db.Queryable().Where("id=@id", new { id = 1 }).ToList(); //id=@id or name like '%'+@name+'%' - var list5 = db.Queryable().Where("id=@id or name like '%'+@name+'%' ", new { id = 1, name = "jack" }).ToList(); + var list5 = db.Queryable().Where("id=@id or name like @name", new { id = 1, name = "%jack%" }).ToList(); @@ -323,7 +323,7 @@ namespace OrmTest { return new SqlSugarClient(new ConnectionConfig() { - DbType = SqlSugar.DbType.SqlServer, + DbType = SqlSugar.DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/Demo2_Updateable.cs b/Src/Asp.Net/OracleTest/Demo/Demo2_Updateable.cs index a4caa3045..3938edd31 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo2_Updateable.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo2_Updateable.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, @@ -78,8 +78,8 @@ namespace OrmTest var dtList = new List>(); dtList.Add(dt); - var t66 = db.Updateable(dt).AS("[Order]").WhereColumns("id").ExecuteCommand(); - var t666 = db.Updateable(dtList).AS("[Order]").WhereColumns("id").ExecuteCommand(); + var t66 = db.Updateable(dt).AS("Order").WhereColumns("id").ExecuteCommand(); + var t666 = db.Updateable(dtList).AS("Order").WhereColumns("id").ExecuteCommand(); diff --git a/Src/Asp.Net/OracleTest/Demo/Demo3_Insertable.cs b/Src/Asp.Net/OracleTest/Demo/Demo3_Insertable.cs index e366d0f3e..9e3d43b07 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo3_Insertable.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo3_Insertable.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/Demo4_Deleteable.cs b/Src/Asp.Net/OracleTest/Demo/Demo4_Deleteable.cs index 8e39e2013..8d8bdd8b7 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo4_Deleteable.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo4_Deleteable.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/Demo5_SqlQueryable.cs b/Src/Asp.Net/OracleTest/Demo/Demo5_SqlQueryable.cs index e98be52a1..fadd3d2a1 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo5_SqlQueryable.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo5_SqlQueryable.cs @@ -16,7 +16,7 @@ namespace OrmTest Console.WriteLine("#### SqlQueryable Start ####"); SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true diff --git a/Src/Asp.Net/OracleTest/Demo/Demo6_Queue.cs b/Src/Asp.Net/OracleTest/Demo/Demo6_Queue.cs index 666fd27ee..314279be9 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo6_Queue.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo6_Queue.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/Demo7_Ado.cs b/Src/Asp.Net/OracleTest/Demo/Demo7_Ado.cs index a4a7ba2db..be5533187 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo7_Ado.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo7_Ado.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/Demo8_Saveable.cs b/Src/Asp.Net/OracleTest/Demo/Demo8_Saveable.cs index 79a1ce33a..5afdb3230 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo8_Saveable.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo8_Saveable.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/Demo9_EntityMain.cs b/Src/Asp.Net/OracleTest/Demo/Demo9_EntityMain.cs index be795b098..fee0ad0e0 100644 --- a/Src/Asp.Net/OracleTest/Demo/Demo9_EntityMain.cs +++ b/Src/Asp.Net/OracleTest/Demo/Demo9_EntityMain.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/DemoA_DbMain.cs b/Src/Asp.Net/OracleTest/Demo/DemoA_DbMain.cs index 206cd6507..7a36baea8 100644 --- a/Src/Asp.Net/OracleTest/Demo/DemoA_DbMain.cs +++ b/Src/Asp.Net/OracleTest/Demo/DemoA_DbMain.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/DemoB_Aop.cs b/Src/Asp.Net/OracleTest/Demo/DemoB_Aop.cs index 617d682ec..b5405146b 100644 --- a/Src/Asp.Net/OracleTest/Demo/DemoB_Aop.cs +++ b/Src/Asp.Net/OracleTest/Demo/DemoB_Aop.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true diff --git a/Src/Asp.Net/OracleTest/Demo/DemoD_DbFirst.cs b/Src/Asp.Net/OracleTest/Demo/DemoD_DbFirst.cs index db57e0938..46b9c9aba 100644 --- a/Src/Asp.Net/OracleTest/Demo/DemoD_DbFirst.cs +++ b/Src/Asp.Net/OracleTest/Demo/DemoD_DbFirst.cs @@ -14,7 +14,7 @@ namespace OrmTest Console.WriteLine("#### DbFirst Start ####"); SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true diff --git a/Src/Asp.Net/OracleTest/Demo/DemoE_CodeFirst.cs b/Src/Asp.Net/OracleTest/Demo/DemoE_CodeFirst.cs index 8692517e1..a73dbfd3e 100644 --- a/Src/Asp.Net/OracleTest/Demo/DemoE_CodeFirst.cs +++ b/Src/Asp.Net/OracleTest/Demo/DemoE_CodeFirst.cs @@ -14,12 +14,11 @@ namespace OrmTest Console.WriteLine("#### CodeFirst Start ####"); SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString3, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true }); - db.DbMaintenance.CreateDatabase(); db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1 db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand(); var list = db.Queryable().ToList(); diff --git a/Src/Asp.Net/OracleTest/Demo/DemoF_Utilities.cs b/Src/Asp.Net/OracleTest/Demo/DemoF_Utilities.cs index 7db24c350..11706e7af 100644 --- a/Src/Asp.Net/OracleTest/Demo/DemoF_Utilities.cs +++ b/Src/Asp.Net/OracleTest/Demo/DemoF_Utilities.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/DemoG_SimpleClient.cs b/Src/Asp.Net/OracleTest/Demo/DemoG_SimpleClient.cs index 21b7208e8..ce9db7d80 100644 --- a/Src/Asp.Net/OracleTest/Demo/DemoG_SimpleClient.cs +++ b/Src/Asp.Net/OracleTest/Demo/DemoG_SimpleClient.cs @@ -16,7 +16,7 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/Demo/Democ_GobalFilter.cs b/Src/Asp.Net/OracleTest/Demo/Democ_GobalFilter.cs index 2406df714..e958c3986 100644 --- a/Src/Asp.Net/OracleTest/Demo/Democ_GobalFilter.cs +++ b/Src/Asp.Net/OracleTest/Demo/Democ_GobalFilter.cs @@ -38,7 +38,7 @@ namespace OrmTest public static SqlSugarClient GetInstance() { - SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.SqlServer, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true }); //single table query gobal filter db.QueryFilter.Add(new SqlFilterItem() diff --git a/Src/Asp.Net/OracleTest/Models/Mapper.cs b/Src/Asp.Net/OracleTest/Models/Mapper.cs index 8d7991d6c..bc0b1ed6a 100644 --- a/Src/Asp.Net/OracleTest/Models/Mapper.cs +++ b/Src/Asp.Net/OracleTest/Models/Mapper.cs @@ -30,7 +30,7 @@ namespace OrmTest } public class ABMapping { - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [SugarColumn(IsPrimaryKey = true,OracleSequenceName = "SEQ_ID")] public int AId { get; set; } public int BId { get; set; } [SugarColumn(IsIgnore = true)] @@ -41,13 +41,13 @@ namespace OrmTest } public class A { - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [SugarColumn(IsPrimaryKey = true, OracleSequenceName ="SEQ_ID")] public int Id { get; set; } public string Name { get; set; } } public class B { - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [SugarColumn(IsPrimaryKey = true, OracleSequenceName = "SEQ_ID")] public int Id { get; set; } public string Name { get; set; } } diff --git a/Src/Asp.Net/OracleTest/Models/Order.cs b/Src/Asp.Net/OracleTest/Models/Order.cs index d7ff068b8..50583871b 100644 --- a/Src/Asp.Net/OracleTest/Models/Order.cs +++ b/Src/Asp.Net/OracleTest/Models/Order.cs @@ -9,7 +9,7 @@ namespace OrmTest public class Order { - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [SugarColumn(IsPrimaryKey = true, OracleSequenceName ="Seq_Id")] public int Id { get; set; } public string Name { get; set; } diff --git a/Src/Asp.Net/OracleTest/Models/OrderItem.cs b/Src/Asp.Net/OracleTest/Models/OrderItem.cs index ae3262c7c..bcfba7906 100644 --- a/Src/Asp.Net/OracleTest/Models/OrderItem.cs +++ b/Src/Asp.Net/OracleTest/Models/OrderItem.cs @@ -8,7 +8,7 @@ namespace OrmTest [SqlSugar.SugarTable("OrderDetail")] public class OrderItem { - [SqlSugar.SugarColumn(IsPrimaryKey =true, IsIdentity =true)] + [SqlSugar.SugarColumn(IsPrimaryKey =true, OracleSequenceName = "Seq_Id")] public int ItemId { get; set; } public int OrderId { get; set; } public decimal? Price { get; set; } diff --git a/Src/Asp.Net/OracleTest/OldTest/Demos/7_Filter.cs b/Src/Asp.Net/OracleTest/OldTest/Demos/7_Filter.cs index 273f6f814..30f245fbe 100644 --- a/Src/Asp.Net/OracleTest/OldTest/Demos/7_Filter.cs +++ b/Src/Asp.Net/OracleTest/OldTest/Demos/7_Filter.cs @@ -39,7 +39,7 @@ namespace OrmTest.Demo public static SqlSugarClient GetInstance1() { - SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Oracle, IsAutoCloseConnection = true }); db.QueryFilter .Add(new SqlFilterItem() { diff --git a/Src/Asp.Net/OracleTest/OldTest/PerformanceTesting/SqlSugarPerformance.cs b/Src/Asp.Net/OracleTest/OldTest/PerformanceTesting/SqlSugarPerformance.cs index 5299a8813..c2cfbf75f 100644 --- a/Src/Asp.Net/OracleTest/OldTest/PerformanceTesting/SqlSugarPerformance.cs +++ b/Src/Asp.Net/OracleTest/OldTest/PerformanceTesting/SqlSugarPerformance.cs @@ -19,7 +19,7 @@ namespace OrmTest.PerformanceTesting SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, - DbType = DbType.SqlServer, + DbType = DbType.Oracle, IsAutoCloseConnection = false }); db.IgnoreColumns.Add("TestId", "Student"); diff --git a/Src/Asp.Net/OracleTest/OldTest/UnitTest/Mapping .cs b/Src/Asp.Net/OracleTest/OldTest/UnitTest/Mapping .cs index db4f2166c..db0383b42 100644 --- a/Src/Asp.Net/OracleTest/OldTest/UnitTest/Mapping .cs +++ b/Src/Asp.Net/OracleTest/OldTest/UnitTest/Mapping .cs @@ -51,12 +51,12 @@ namespace OrmTest.UnitTest public new SqlSugarClient GetInstance() { - SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.Oracle, IsAutoCloseConnection = true }); return db; } public SqlSugarClient GetInstance2() { - SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.Oracle, IsAutoCloseConnection = true }); db.Aop.OnLogExecuting = (sql, pars) => { Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars)); diff --git a/Src/Asp.Net/OracleTest/OldTest/UnitTest/Query/JoinQuery.cs b/Src/Asp.Net/OracleTest/OldTest/UnitTest/Query/JoinQuery.cs index 3ae48fbed..e4d934011 100644 --- a/Src/Asp.Net/OracleTest/OldTest/UnitTest/Query/JoinQuery.cs +++ b/Src/Asp.Net/OracleTest/OldTest/UnitTest/Query/JoinQuery.cs @@ -128,7 +128,7 @@ namespace OrmTest.UnitTest public new SqlSugarClient GetInstance() { - SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Oracle }); db.Aop.OnLogExecuting = (sql, pars) => { Console.WriteLine(sql + " " + pars); diff --git a/Src/Asp.Net/OracleTest/OldTest/UnitTest/UnitTestBase.cs b/Src/Asp.Net/OracleTest/OldTest/UnitTest/UnitTestBase.cs index 1aeea8b30..855a6e78c 100644 --- a/Src/Asp.Net/OracleTest/OldTest/UnitTest/UnitTestBase.cs +++ b/Src/Asp.Net/OracleTest/OldTest/UnitTest/UnitTestBase.cs @@ -48,7 +48,7 @@ namespace OrmTest.UnitTest public SqlSugarClient GetInstance() { - SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Oracle, IsAutoCloseConnection = true }); return db; } } diff --git a/Src/Asp.Net/OracleTest/UnitTest/Main.cs b/Src/Asp.Net/OracleTest/UnitTest/Main.cs index c81b373f5..02034efc6 100644 --- a/Src/Asp.Net/OracleTest/UnitTest/Main.cs +++ b/Src/Asp.Net/OracleTest/UnitTest/Main.cs @@ -10,7 +10,7 @@ namespace OrmTest { public static SqlSugarClient Db=> new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, @@ -28,6 +28,9 @@ namespace OrmTest { Db.DbMaintenance.TruncateTable(); Db.DbMaintenance.TruncateTable(); + Db.DbMaintenance.TruncateTable(); + Db.DbMaintenance.TruncateTable(); + Db.DbMaintenance.TruncateTable(); } public static void Init() { diff --git a/Src/Asp.Net/OracleTest/UnitTest/UThread.cs b/Src/Asp.Net/OracleTest/UnitTest/UThread.cs index 48bf67da5..9ab5dc6f6 100644 --- a/Src/Asp.Net/OracleTest/UnitTest/UThread.cs +++ b/Src/Asp.Net/OracleTest/UnitTest/UThread.cs @@ -12,7 +12,7 @@ namespace OrmTest public static SqlSugarClient simpleDb => new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, @@ -27,7 +27,7 @@ namespace OrmTest }); public static SqlSugarClient ssDb => new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, @@ -43,7 +43,7 @@ namespace OrmTest }); public static SqlSugarClient singleDb = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, @@ -58,7 +58,7 @@ namespace OrmTest }); public static SqlSugarClient singleAndSsDb = new SqlSugarClient(new ConnectionConfig() { - DbType = DbType.SqlServer, + DbType = DbType.Oracle, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, diff --git a/Src/Asp.Net/OracleTest/UnitTest/Updateable.cs b/Src/Asp.Net/OracleTest/UnitTest/Updateable.cs index 2397d6032..64ec9a824 100644 --- a/Src/Asp.Net/OracleTest/UnitTest/Updateable.cs +++ b/Src/Asp.Net/OracleTest/UnitTest/Updateable.cs @@ -43,16 +43,16 @@ namespace OrmTest { IsRemind = saveDiary.IsRemind, }).Where(it => it.ID == saveDiary.ID).ToSql(); - UValidate.Check(sql.Key, @"UPDATE [Diary] SET - [IsRemind] = @Const0 WHERE ( [ID] = @ID1 )", "Updateable"); + UValidate.Check(sql.Key, @"UPDATE ""DIARY"" SET + ""ISREMIND"" = @Const0 WHERE ( ""ID"" = @ID1 )", "Updateable"); sql = Db.Updateable().SetColumns(it => new UnitDiary() { TypeID = saveDiary.TypeID, }).Where(it => it.ID == saveDiary.ID).ToSql(); - UValidate.Check(sql.Key, @"UPDATE [Diary] SET - [TypeID] = @Const0 WHERE ( [ID] = @ID1 )", "Updateable"); + UValidate.Check(sql.Key, @"UPDATE ""DIARY"" SET + ""TYPEID"" = @Const0 WHERE ( ""ID"" = @ID1 )", "Updateable"); } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs index 07da2a3f6..b45a3d4ee 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs @@ -45,6 +45,10 @@ namespace SqlSugar var regex = @"^AND (\@Const\d+) $"; + if (this.Context is OracleExpressionContext) + { + regex = @"^AND (\:Const\d+) $"; + } if (Regex.IsMatch(result, regex)) { result = "AND " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value; diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs index 3e287c40b..7174e5cfc 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubWhere.cs @@ -45,6 +45,10 @@ namespace SqlSugar var regex = @"^WHERE (\@Const\d+) $"; + if (this.Context is OracleExpressionContext) + { + regex = @"^WHERE (\:Const\d+) $"; + } if (Regex.IsMatch(result, regex)) { result = "WHERE " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value; diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs index f09fc43c3..c7d3589b1 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs @@ -357,7 +357,7 @@ namespace SqlSugar private List GetColumnInfosByTableName(string tableName) { - string sql = "select * from " + tableName + " WHERE 1=2 "; + string sql = "select * from " +SqlBuilder.GetTranslationTableName(tableName) + " WHERE 1=2 "; var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent; this.Context.Ado.IsEnableLogEvent = false; using (DbDataReader reader = (DbDataReader)this.Context.Ado.GetDataReader(sql)) diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs index b0705db10..ecec0cd9f 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs @@ -16,6 +16,7 @@ namespace SqlSugar { this.FormatSql = sql => { + sql = sql.Replace("+@", "+:"); if (sql.HasValue()&&sql.Contains("@")) { var exceptionalCaseInfo = Regex.Matches(sql, @"\'.*?\@.*?\'| [\.,\w]+\@[\.,\w]+ | [\.,\w]+\@[\.,\w]+"); if (exceptionalCaseInfo != null) {