Browse Source

Update Demo

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
996bef1aa1
  1. 16
      Src/Asp.Net/MySqlTest/Demo/Demo0_SqlSugarClient.cs
  2. 6
      Src/Asp.Net/MySqlTest/Demo/Demo1_Queryable.cs
  3. 6
      Src/Asp.Net/MySqlTest/Demo/Demo2_Updateable.cs
  4. 2
      Src/Asp.Net/MySqlTest/Demo/Demo3_Insertable.cs
  5. 2
      Src/Asp.Net/MySqlTest/Demo/Demo4_Deleteable.cs
  6. 8
      Src/Asp.Net/MySqlTest/Demo/Demo5_SqlQueryable.cs
  7. 4
      Src/Asp.Net/MySqlTest/Demo/Demo6_Queue.cs
  8. 10
      Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs
  9. 2
      Src/Asp.Net/MySqlTest/Demo/Demo8_Saveable.cs
  10. 2
      Src/Asp.Net/MySqlTest/Demo/Demo9_EntityMain.cs
  11. 2
      Src/Asp.Net/MySqlTest/Demo/DemoA_DbMain.cs
  12. 2
      Src/Asp.Net/MySqlTest/Demo/DemoB_Aop.cs
  13. 2
      Src/Asp.Net/MySqlTest/Demo/DemoD_DbFirst.cs
  14. 2
      Src/Asp.Net/MySqlTest/Demo/DemoE_CodeFirst.cs
  15. 4
      Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs
  16. 2
      Src/Asp.Net/MySqlTest/Demo/DemoG_SimpleClient.cs
  17. 10
      Src/Asp.Net/MySqlTest/Demo/Democ_GobalFilter.cs
  18. 2
      Src/Asp.Net/MySqlTest/UnitTest/Main.cs
  19. 4
      Src/Asp.Net/MySqlTest/UnitTest/UAdo.cs
  20. 6
      Src/Asp.Net/MySqlTest/UnitTest/UQueryable.cs
  21. 8
      Src/Asp.Net/MySqlTest/UnitTest/UThread.cs

16
Src/Asp.Net/MySqlTest/Demo/Demo0_SqlSugarClient.cs

@ -28,7 +28,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,//Master Connection
DbType = DbType.SqlServer,
DbType = DbType.MySql,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
@ -53,7 +53,7 @@ namespace OrmTest
Console.WriteLine("#### SqlSugarClient Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
@ -146,7 +146,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
ConfigureExternalServices = new ConfigureExternalServices()
@ -209,7 +209,7 @@ namespace OrmTest
new ConnectionConfig()
{
ConfigId = 1,
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
@ -226,8 +226,8 @@ namespace OrmTest
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}
new ConnectionConfig(){ ConfigId="1", DbType=DbType.MySql, ConnectionString=Config.ConnectionString,InitKeyType=InitKeyType.Attribute,IsAutoCloseConnection=true },
new ConnectionConfig(){ ConfigId="2", DbType=DbType.MySql, ConnectionString=Config.ConnectionString2 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true}
});
//use db1
@ -352,7 +352,7 @@ namespace OrmTest
Db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
AopEvents = new AopEvents()
@ -386,7 +386,7 @@ namespace OrmTest
Db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
AopEvents = new AopEvents()

6
Src/Asp.Net/MySqlTest/Demo/Demo1_Queryable.cs

@ -189,7 +189,7 @@ namespace OrmTest
Console.WriteLine("#### No Entity Start ####");
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();
Console.WriteLine("#### No Entity End ####");
@ -252,7 +252,7 @@ namespace OrmTest
//id=@id
var list4 = db.Queryable<Order>().Where("id=@id", new { id = 1 }).ToList();
//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()
{
DbType = SqlSugar.DbType.SqlServer,
DbType = SqlSugar.DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,

6
Src/Asp.Net/MySqlTest/Demo/Demo2_Updateable.cs

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
@ -78,8 +78,8 @@ namespace OrmTest
var dtList = new List<Dictionary<string, object>>();
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();

2
Src/Asp.Net/MySqlTest/Demo/Demo3_Insertable.cs

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

2
Src/Asp.Net/MySqlTest/Demo/Demo4_Deleteable.cs

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

8
Src/Asp.Net/MySqlTest/Demo/Demo5_SqlQueryable.cs

@ -16,20 +16,20 @@ namespace OrmTest
Console.WriteLine("#### SqlQueryable Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true
});
int total = 0;
var list = db.SqlQueryable<Student>("select * from [order]").ToPageList(1, 2, ref total);
var list = db.SqlQueryable<Student>("select * from `order`").ToPageList(1, 2, ref total);
//by expression
var list2 = db.SqlQueryable<Student>("select * from [order]").Where(it => it.Id == 1).ToPageList(1, 2);
var list2 = db.SqlQueryable<Student>("select * from `order`").Where(it => it.Id == 1).ToPageList(1, 2);
//by sql
var list3 = db.SqlQueryable<Student>("select * from [order]").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
var list3 = db.SqlQueryable<Student>("select * from `order`").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
Console.WriteLine("#### SqlQueryable End ####");
}

4
Src/Asp.Net/MySqlTest/Demo/Demo6_Queue.cs

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
@ -43,7 +43,7 @@ namespace OrmTest
db.Queryable<Order>().AddQueue();
db.Queryable<Order>().AddQueue();
db.AddQueue("select * from [Order] where id=@id", new { id = 10000 });
db.AddQueue("select * from `order` where id=@id", new { id = 10000 });
var result2 = db.SaveQueues<Order, Order, Order>();
Console.WriteLine("#### Queue End ####");

10
Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
@ -30,13 +30,13 @@ namespace OrmTest
}
});
//sql
var dt = db.Ado.GetDataTable("select * from [order] where @id>0 or name=@name", new List<SugarParameter>(){
var dt = db.Ado.GetDataTable("select * from `order` where @id>0 or name=@name", new List<SugarParameter>(){
new SugarParameter("@id",1),
new SugarParameter("@name","2")
});
//sql
var dt2 = db.Ado.GetDataTable("select * from [order] where @id>0 or name=@name", new { id = 1, name = "2" });
var dt2 = db.Ado.GetDataTable("select * from `order` where @id>0 or name=@name", new { id = 1, name = "2" });
//Stored Procedure
//var dt3 = db.Ado.UseStoredProcedure().GetDataTable("sp_school", new { name = "张三", age = 0 });
@ -47,9 +47,9 @@ namespace OrmTest
//There are many methods to under db.ado
var list= db.Ado.SqlQuery<Order>("select * from [order] ");
var list= db.Ado.SqlQuery<Order>("select * from `order` ");
var intValue=db.Ado.SqlQuerySingle<int>("select 1");
db.Ado.ExecuteCommand("delete [order] where id>1000");
db.Ado.ExecuteCommand("delete from `order` where id>1000");
//db.Ado.xxx
Console.WriteLine("#### Ado End ####");
}

2
Src/Asp.Net/MySqlTest/Demo/Demo8_Saveable.cs

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

2
Src/Asp.Net/MySqlTest/Demo/Demo9_EntityMain.cs

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

2
Src/Asp.Net/MySqlTest/Demo/DemoA_DbMain.cs

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

2
Src/Asp.Net/MySqlTest/Demo/DemoB_Aop.cs

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

2
Src/Asp.Net/MySqlTest/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.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true

2
Src/Asp.Net/MySqlTest/Demo/DemoE_CodeFirst.cs

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

4
Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs

@ -16,7 +16,7 @@ namespace OrmTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
@ -37,7 +37,7 @@ namespace OrmTest
Console.WriteLine(string.Join("," ,list));
});
var list2= db.Utilities.DataTableToList<Order>(db.Ado.GetDataTable("select * from [order]"));
var list2= db.Utilities.DataTableToList<Order>(db.Ado.GetDataTable("select * from `order`"));
//more https://github.com/sunkaixuan/SqlSugar/wiki/f.Utilities
Console.WriteLine("#### Utilities End ####");

2
Src/Asp.Net/MySqlTest/Demo/DemoG_SimpleClient.cs

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

10
Src/Asp.Net/MySqlTest/Demo/Democ_GobalFilter.cs

@ -16,21 +16,21 @@ namespace OrmTest
var sql = db.Queryable<Order>().ToSql();
//SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] WHERE isDelete=0
//SELECT [Id],[Name],[Price],[CreateTime] FROM `order` WHERE isDelete=0
Console.WriteLine(sql);
var sql2 = db.Queryable<Order,OrderItem>((main,ot)=> main.Id==ot.OrderId).ToSql();
//SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] main ,[OrderDetail] ot WHERE ( [main].[Id] = [ot].[OrderId] ) AND main.isDelete=0
//SELECT [Id],[Name],[Price],[CreateTime] FROM `order` main ,[OrderDetail] ot WHERE ( [main].[Id] = [ot].[OrderId] ) AND main.isDelete=0
Console.WriteLine(sql2);
var sql3 = db.Queryable<Order>().Filter("Myfilter").ToSql();// Myfilter+Gobal
//SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] WHERE Name='jack' AND isDelete=0
//SELECT [Id],[Name],[Price],[CreateTime] FROM `order` WHERE Name='jack' AND isDelete=0
Console.WriteLine(sql3);
var sql4 = db.Queryable<Order>().Filter("Myfilter",isDisabledGobalFilter:true).ToSql();//only Myfilter
//SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] WHERE Name='jack'
//SELECT [Id],[Name],[Price],[CreateTime] FROM `order` WHERE Name='jack'
Console.WriteLine(sql4);
Console.WriteLine("#### Filter End ####");
}
@ -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.MySql, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true });
//single table query gobal filter
db.QueryFilter.Add(new SqlFilterItem()

2
Src/Asp.Net/MySqlTest/UnitTest/Main.cs

@ -10,7 +10,7 @@ namespace OrmTest
{
public static SqlSugarClient Db=> new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,

4
Src/Asp.Net/MySqlTest/UnitTest/UAdo.cs

@ -48,9 +48,9 @@ namespace OrmTest
task8.Wait();
UValidate.Check(8, task8.Result[0].id, "ado");
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from [order];select * from OrderDetail");
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from `order`;select * from OrderDetail");
var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from [order];select * from OrderDetail");
var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from `order`;select * from OrderDetail");
task10.Wait();
}
}

6
Src/Asp.Net/MySqlTest/UnitTest/UQueryable.cs

@ -46,11 +46,11 @@ namespace OrmTest
[Dc]=@Dc,[IntNull]=@IntNull WHERE [Int]=@Int", "Queryable");
sql = Db.Queryable<Order>().IgnoreColumns(it => it.CreateTime).ToSql().Key;
UValidate.Check(sql, "SELECT [Id],[Name],[Price],[CustomId] FROM [Order] ", "Queryable");
UValidate.Check(sql, "SELECT [Id],[Name],[Price],[CustomId] FROM `order` ", "Queryable");
sql = Db.Queryable<Order>().IgnoreColumns(it => new { it.Id, it.Name }).ToSql().Key;
UValidate.Check(sql, "SELECT [Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");
UValidate.Check(sql, "SELECT [Price],[CreateTime],[CustomId] FROM `order` ", "Queryable");
sql = Db.Queryable<Order>().IgnoreColumns("id").ToSql().Key;
UValidate.Check(sql, "SELECT [Name],[Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");
UValidate.Check(sql, "SELECT [Name],[Price],[CreateTime],[CustomId] FROM `order` ", "Queryable");
var cts = IEnumerbleContains.Data();
var list2=Db.Queryable<Order>()

8
Src/Asp.Net/MySqlTest/UnitTest/UThread.cs

@ -12,7 +12,7 @@ namespace OrmTest
public static SqlSugarClient simpleDb => new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
DbType = DbType.MySql,
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.MySql,
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.MySql,
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.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,

Loading…
Cancel
Save