Update demo

This commit is contained in:
sunkaixuan 2019-06-04 20:01:28 +08:00
parent 76d4dfef87
commit 4ea9b897e2
32 changed files with 70 additions and 173 deletions

View File

@ -17,7 +17,6 @@ namespace OrmTest
SqlSugarClient();//Create db SqlSugarClient();//Create db
DbContext();//Optimizing SqlSugarClient usage DbContext();//Optimizing SqlSugarClient usage
SingletonPattern();//Singleten Pattern SingletonPattern();//Singleten Pattern
DistributedTransactionExample();
MasterSlave();//Read-write separation MasterSlave();//Read-write separation
CustomAttribute(); CustomAttribute();
} }
@ -29,7 +28,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
ConnectionString = Config.ConnectionString,//Master Connection ConnectionString = Config.ConnectionString,//Master Connection
DbType = DbType.SqlServer, DbType = DbType.Oracle,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() { SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
@ -37,6 +36,7 @@ namespace OrmTest
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }
} }
}); });
db.Aop.OnLogExecuted = (s, p) => db.Aop.OnLogExecuted = (s, p) =>
{ {
Console.WriteLine(db.Ado.Connection.ConnectionString); Console.WriteLine(db.Ado.Connection.ConnectionString);
@ -54,7 +54,7 @@ namespace OrmTest
Console.WriteLine("#### SqlSugarClient Start ####"); Console.WriteLine("#### SqlSugarClient Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, 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 //Use db query
var dt = db.Ado.GetDataTable("select 1"); var dt = db.Ado.GetDataTable("select 1 from dual");
//Create tables //Create tables
db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order)); db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order));
@ -147,7 +153,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer, DbType = DbType.Oracle,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
ConfigureExternalServices = new ConfigureExternalServices() ConfigureExternalServices = new ConfigureExternalServices()
@ -210,7 +216,7 @@ namespace OrmTest
new ConnectionConfig() new ConnectionConfig()
{ {
ConfigId = 1, ConfigId = 1,
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
@ -219,126 +225,6 @@ namespace OrmTest
OnLogExecuting = (sql, p) => { Console.WriteLine(sql); } OnLogExecuting = (sql, p) => { Console.WriteLine(sql); }
} }
}); });
private static void DistributedTransactionExample()
{
Console.WriteLine("");
Console.WriteLine("#### Distributed TransactionExample Start ####");
SqlSugarClient db = new SqlSugarClient(new List<ConnectionConfig>()
{
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<Order>().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<Order>().Count());
// Example 1
Console.WriteLine("Example 1");
try
{
db.BeginTran();
db.ChangeDatabase("1");//use db1
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().Count());
db.ChangeDatabase("2");//use db2
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().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<Order>().Count());
db.ChangeDatabase("2");//use db2
Console.WriteLine(db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().Count());
}
// Example 2
Console.WriteLine("Example 2");
var result=db.UseTran(() =>
{
db.ChangeDatabase("1");//use db1
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().Count());
db.ChangeDatabase("2");//use db2
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().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<Order>().Count());
db.ChangeDatabase("2");//use db2
Console.WriteLine(db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().Count());
}
// Example 3
Console.WriteLine("Example 3");
var result2 = db.UseTranAsync(() =>
{
db.ChangeDatabase("1");//use db1
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().Count());
db.ChangeDatabase("2");//use db2
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().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<Order>().Count());
db.ChangeDatabase("2");//use mysql
Console.WriteLine(db.CurrentConnectionConfig.DbType);
Console.WriteLine(db.Queryable<Order>().Count());
}
Console.WriteLine("#### Distributed TransactionExample End ####");
}
} }
/// <summary> /// <summary>
@ -353,7 +239,7 @@ namespace OrmTest
Db = new SqlSugarClient(new ConnectionConfig() Db = new SqlSugarClient(new ConnectionConfig()
{ {
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer, DbType = DbType.Oracle,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
AopEvents = new AopEvents() AopEvents = new AopEvents()
@ -387,7 +273,7 @@ namespace OrmTest
Db = new SqlSugarClient(new ConnectionConfig() Db = new SqlSugarClient(new ConnectionConfig()
{ {
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer, DbType = DbType.Oracle,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
AopEvents = new AopEvents() AopEvents = new AopEvents()

View File

@ -171,7 +171,7 @@ namespace OrmTest
.Mapper(it => it.B, it => it.BId).ToList(); .Mapper(it => it.B, it => it.BId).ToList();
//Manual mode //Manual mode
var result = db.Queryable<OrderInfo>().Take(10).Select<ViewOrder>().Mapper((itemModel, cache) => var result = db.Queryable<OrderInfo>().Select<ViewOrder>().Mapper((itemModel, cache) =>
{ {
var allItems = cache.Get(orderList => { var allItems = cache.Get(orderList => {
var allIds = orderList.Select(it => it.Id).ToList(); var allIds = orderList.Select(it => it.Id).ToList();
@ -189,7 +189,7 @@ namespace OrmTest
Console.WriteLine("#### No Entity Start ####"); Console.WriteLine("#### No Entity Start ####");
var db = GetInstance(); var db = GetInstance();
var list = db.Queryable<dynamic>().AS("order ").Where("id=id", new { id = 1 }).ToList(); var list = db.Queryable<dynamic>().AS("order").Where("id=id", new { id = 1 }).ToList();
var list2 = db.Queryable<dynamic>("o").AS("order").AddJoinInfo("OrderDetail", "i", "o.id=i.OrderId").Where("id=id", new { id = 1 }).Select("o.*").ToList(); var list2 = db.Queryable<dynamic>("o").AS("order").AddJoinInfo("OrderDetail", "i", "o.id=i.OrderId").Where("id=id", new { id = 1 }).Select("o.*").ToList();
Console.WriteLine("#### No Entity End ####"); Console.WriteLine("#### No Entity End ####");
@ -252,7 +252,7 @@ namespace OrmTest
//id=@id //id=@id
var list4 = db.Queryable<Order>().Where("id=@id", new { id = 1 }).ToList(); var list4 = db.Queryable<Order>().Where("id=@id", new { id = 1 }).ToList();
//id=@id or name like '%'+@name+'%' //id=@id or name like '%'+@name+'%'
var list5 = db.Queryable<Order>().Where("id=@id or name like '%'+@name+'%' ", new { id = 1, name = "jack" }).ToList(); var list5 = db.Queryable<Order>().Where("id=@id or name like @name", new { id = 1, name = "%jack%" }).ToList();
@ -323,7 +323,7 @@ namespace OrmTest
{ {
return new SqlSugarClient(new ConnectionConfig() return new SqlSugarClient(new ConnectionConfig()
{ {
DbType = SqlSugar.DbType.SqlServer, DbType = SqlSugar.DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
@ -78,8 +78,8 @@ namespace OrmTest
var dtList = new List<Dictionary<string, object>>(); var dtList = new List<Dictionary<string, object>>();
dtList.Add(dt); dtList.Add(dt);
var t66 = db.Updateable(dt).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(); var t666 = db.Updateable(dtList).AS("Order").WhereColumns("id").ExecuteCommand();

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
Console.WriteLine("#### SqlQueryable Start ####"); Console.WriteLine("#### SqlQueryable Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true IsAutoCloseConnection = true

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true IsAutoCloseConnection = true

View File

@ -14,7 +14,7 @@ namespace OrmTest
Console.WriteLine("#### DbFirst Start ####"); Console.WriteLine("#### DbFirst Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true IsAutoCloseConnection = true

View File

@ -14,12 +14,11 @@ namespace OrmTest
Console.WriteLine("#### CodeFirst Start ####"); Console.WriteLine("#### CodeFirst Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString3, ConnectionString = Config.ConnectionString3,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true IsAutoCloseConnection = true
}); });
db.DbMaintenance.CreateDatabase();
db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1 db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1
db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand(); db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand();
var list = db.Queryable<CodeFirstTable1>().ToList(); var list = db.Queryable<CodeFirstTable1>().ToList();

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -38,7 +38,7 @@ namespace OrmTest
public static SqlSugarClient GetInstance() 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 //single table query gobal filter
db.QueryFilter.Add(new SqlFilterItem() db.QueryFilter.Add(new SqlFilterItem()

View File

@ -30,7 +30,7 @@ namespace OrmTest
} }
public class ABMapping public class ABMapping
{ {
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SugarColumn(IsPrimaryKey = true,OracleSequenceName = "SEQ_ID")]
public int AId { get; set; } public int AId { get; set; }
public int BId { get; set; } public int BId { get; set; }
[SugarColumn(IsIgnore = true)] [SugarColumn(IsIgnore = true)]
@ -41,13 +41,13 @@ namespace OrmTest
} }
public class A public class A
{ {
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SugarColumn(IsPrimaryKey = true, OracleSequenceName ="SEQ_ID")]
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
} }
public class B public class B
{ {
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SugarColumn(IsPrimaryKey = true, OracleSequenceName = "SEQ_ID")]
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
} }

View File

@ -9,7 +9,7 @@ namespace OrmTest
public class Order public class Order
{ {
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SugarColumn(IsPrimaryKey = true, OracleSequenceName ="Seq_Id")]
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }

View File

@ -8,7 +8,7 @@ namespace OrmTest
[SqlSugar.SugarTable("OrderDetail")] [SqlSugar.SugarTable("OrderDetail")]
public class OrderItem public class OrderItem
{ {
[SqlSugar.SugarColumn(IsPrimaryKey =true, IsIdentity =true)] [SqlSugar.SugarColumn(IsPrimaryKey =true, OracleSequenceName = "Seq_Id")]
public int ItemId { get; set; } public int ItemId { get; set; }
public int OrderId { get; set; } public int OrderId { get; set; }
public decimal? Price { get; set; } public decimal? Price { get; set; }

View File

@ -39,7 +39,7 @@ namespace OrmTest.Demo
public static SqlSugarClient GetInstance1() 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 db.QueryFilter
.Add(new SqlFilterItem() .Add(new SqlFilterItem()
{ {

View File

@ -19,7 +19,7 @@ namespace OrmTest.PerformanceTesting
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer, DbType = DbType.Oracle,
IsAutoCloseConnection = false IsAutoCloseConnection = false
}); });
db.IgnoreColumns.Add("TestId", "Student"); db.IgnoreColumns.Add("TestId", "Student");

View File

@ -51,12 +51,12 @@ namespace OrmTest.UnitTest
public new SqlSugarClient GetInstance() 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; return db;
} }
public SqlSugarClient GetInstance2() 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) => db.Aop.OnLogExecuting = (sql, pars) =>
{ {
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars)); Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));

View File

@ -128,7 +128,7 @@ namespace OrmTest.UnitTest
public new SqlSugarClient GetInstance() 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) => db.Aop.OnLogExecuting = (sql, pars) =>
{ {
Console.WriteLine(sql + " " + pars); Console.WriteLine(sql + " " + pars);

View File

@ -48,7 +48,7 @@ namespace OrmTest.UnitTest
public SqlSugarClient GetInstance() 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; return db;
} }
} }

View File

@ -10,7 +10,7 @@ namespace OrmTest
{ {
public static SqlSugarClient Db=> new SqlSugarClient(new ConnectionConfig() public static SqlSugarClient Db=> new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
@ -28,6 +28,9 @@ namespace OrmTest
{ {
Db.DbMaintenance.TruncateTable<Order>(); Db.DbMaintenance.TruncateTable<Order>();
Db.DbMaintenance.TruncateTable<OrderItem>(); Db.DbMaintenance.TruncateTable<OrderItem>();
Db.DbMaintenance.TruncateTable<A>();
Db.DbMaintenance.TruncateTable<B>();
Db.DbMaintenance.TruncateTable<ABMapping>();
} }
public static void Init() public static void Init()
{ {

View File

@ -12,7 +12,7 @@ namespace OrmTest
public static SqlSugarClient simpleDb => new SqlSugarClient(new ConnectionConfig() public static SqlSugarClient simpleDb => new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
@ -27,7 +27,7 @@ namespace OrmTest
}); });
public static SqlSugarClient ssDb => new SqlSugarClient(new ConnectionConfig() public static SqlSugarClient ssDb => new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
@ -43,7 +43,7 @@ namespace OrmTest
}); });
public static SqlSugarClient singleDb = new SqlSugarClient(new ConnectionConfig() public static SqlSugarClient singleDb = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
@ -58,7 +58,7 @@ namespace OrmTest
}); });
public static SqlSugarClient singleAndSsDb = new SqlSugarClient(new ConnectionConfig() public static SqlSugarClient singleAndSsDb = new SqlSugarClient(new ConnectionConfig()
{ {
DbType = DbType.SqlServer, DbType = DbType.Oracle,
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,

View File

@ -43,16 +43,16 @@ namespace OrmTest
{ {
IsRemind = saveDiary.IsRemind, IsRemind = saveDiary.IsRemind,
}).Where(it => it.ID == saveDiary.ID).ToSql(); }).Where(it => it.ID == saveDiary.ID).ToSql();
UValidate.Check(sql.Key, @"UPDATE [Diary] SET UValidate.Check(sql.Key, @"UPDATE ""DIARY"" SET
[IsRemind] = @Const0 WHERE ( [ID] = @ID1 )", "Updateable"); ""ISREMIND"" = @Const0 WHERE ( ""ID"" = @ID1 )", "Updateable");
sql = Db.Updateable<UnitDiary>().SetColumns(it => new UnitDiary() sql = Db.Updateable<UnitDiary>().SetColumns(it => new UnitDiary()
{ {
TypeID = saveDiary.TypeID, TypeID = saveDiary.TypeID,
}).Where(it => it.ID == saveDiary.ID).ToSql(); }).Where(it => it.ID == saveDiary.ID).ToSql();
UValidate.Check(sql.Key, @"UPDATE [Diary] SET UValidate.Check(sql.Key, @"UPDATE ""DIARY"" SET
[TypeID] = @Const0 WHERE ( [ID] = @ID1 )", "Updateable"); ""TYPEID"" = @Const0 WHERE ( ""ID"" = @ID1 )", "Updateable");
} }
} }

View File

@ -45,6 +45,10 @@ namespace SqlSugar
var regex = @"^AND (\@Const\d+) $"; var regex = @"^AND (\@Const\d+) $";
if (this.Context is OracleExpressionContext)
{
regex = @"^AND (\:Const\d+) $";
}
if (Regex.IsMatch(result, regex)) if (Regex.IsMatch(result, regex))
{ {
result = "AND " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value; result = "AND " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;

View File

@ -45,6 +45,10 @@ namespace SqlSugar
var regex = @"^WHERE (\@Const\d+) $"; var regex = @"^WHERE (\@Const\d+) $";
if (this.Context is OracleExpressionContext)
{
regex = @"^WHERE (\:Const\d+) $";
}
if (Regex.IsMatch(result, regex)) if (Regex.IsMatch(result, regex))
{ {
result = "WHERE " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value; result = "WHERE " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;

View File

@ -357,7 +357,7 @@ namespace SqlSugar
private List<DbColumnInfo> GetColumnInfosByTableName(string tableName) private List<DbColumnInfo> 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; var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
this.Context.Ado.IsEnableLogEvent = false; this.Context.Ado.IsEnableLogEvent = false;
using (DbDataReader reader = (DbDataReader)this.Context.Ado.GetDataReader(sql)) using (DbDataReader reader = (DbDataReader)this.Context.Ado.GetDataReader(sql))

View File

@ -16,6 +16,7 @@ namespace SqlSugar
{ {
this.FormatSql = sql => this.FormatSql = sql =>
{ {
sql = sql.Replace("+@", "+:");
if (sql.HasValue()&&sql.Contains("@")) { if (sql.HasValue()&&sql.Contains("@")) {
var exceptionalCaseInfo = Regex.Matches(sql, @"\'.*?\@.*?\'| [\.,\w]+\@[\.,\w]+ | [\.,\w]+\@[\.,\w]+"); var exceptionalCaseInfo = Regex.Matches(sql, @"\'.*?\@.*?\'| [\.,\w]+\@[\.,\w]+ | [\.,\w]+\@[\.,\w]+");
if (exceptionalCaseInfo != null) { if (exceptionalCaseInfo != null) {