Browse Source

Update demo

pull/30/head
sunkaixuan 2 years ago
parent
commit
5c8011557e
  1. 6
      Src/Asp.Net/MySqlConnectorTest/Config.cs
  2. 6
      Src/Asp.Net/MySqlConnectorTest/Demo/Demo1_Queryable.cs
  3. 4
      Src/Asp.Net/MySqlConnectorTest/Demo/Demo2_Updateable.cs
  4. 6
      Src/Asp.Net/MySqlConnectorTest/Demo/Demo5_SqlQueryable.cs
  5. 2
      Src/Asp.Net/MySqlConnectorTest/Demo/Demo6_Queue.cs
  6. 12
      Src/Asp.Net/MySqlConnectorTest/Demo/Demo7_Ado.cs
  7. 2
      Src/Asp.Net/MySqlConnectorTest/Demo/DemoF_Utilities.cs
  8. 8
      Src/Asp.Net/MySqlConnectorTest/Demo/Democ_GobalFilter.cs
  9. 4
      Src/Asp.Net/MySqlConnectorTest/UnitTest/UAdo.cs

6
Src/Asp.Net/MySqlConnectorTest/Config.cs

@ -16,17 +16,17 @@ namespace OrmTest
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql;AllowLoadLocalInfile=true";
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=123456;AllowLoadLocalInfile=true";
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
public static string ConnectionString2 = "server=localhost;Database=SqlSugar4xTest2;Uid=root;Pwd=haosql";
public static string ConnectionString2 = "server=localhost;Database=SqlSugar4xTest2;Uid=root;Pwd=123456";
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
public static string ConnectionString3 = "server=localhost;Database=SqlSugar4xTest3;Uid=root;Pwd=haosql";
public static string ConnectionString3 = "server=localhost;Database=SqlSugar4xTest3;Uid=root;Pwd=123456";
/***注意:如果报错:指字关键词不在字典中这说明需要更新MYSQL.DATA驱动到最新,不报错就不需要更新***/

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

@ -188,7 +188,7 @@ namespace OrmTest
var db = GetInstance();
//Creater Table
db.CodeFirst.InitTables(typeof(Tree));
db.DbMaintenance.TruncateTable("tree");
db.DbMaintenance.TruncateTable("Tree");
db.Insertable(new Tree() { Id = 1, Name = "root" }).ExecuteCommand();
db.Insertable(new Tree() { Id = 11, Name = "child1",ParentId=1 }).ExecuteCommand();
db.Insertable(new Tree() { Id = 12, Name = "child2",ParentId=1 }).ExecuteCommand();
@ -247,9 +247,9 @@ 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();
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 ####");
}

4
Src/Asp.Net/MySqlConnectorTest/Demo/Demo2_Updateable.cs

@ -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();

6
Src/Asp.Net/MySqlConnectorTest/Demo/Demo5_SqlQueryable.cs

@ -22,13 +22,13 @@ namespace OrmTest
});
int total = 0;
var list = db.SqlQueryable<Order>("select * from `order`").ToPageList(1, 2, ref total);
var list = db.SqlQueryable<Order>("select * from `Order`").ToPageList(1, 2, ref total);
//by expression
var list2 = db.SqlQueryable<Order>("select * from `order`").Where(it => it.Id == 1).ToPageList(1, 2);
var list2 = db.SqlQueryable<Order>("select * from `Order`").Where(it => it.Id == 1).ToPageList(1, 2);
//by sql
var list3 = db.SqlQueryable<Order>("select * from `order`").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
var list3 = db.SqlQueryable<Order>("select * from `Order`").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
Console.WriteLine("#### SqlQueryable End ####");
}

2
Src/Asp.Net/MySqlConnectorTest/Demo/Demo6_Queue.cs

@ -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 ####");

12
Src/Asp.Net/MySqlConnectorTest/Demo/Demo7_Ado.cs

@ -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,11 +47,11 @@ namespace OrmTest
//There are many methods to under db.ado
var list= db.Ado.SqlQuery<Order>("select * from `order` ");
var list2 = db.Ado.SqlQuery<Order,Order>("select * from `order` where 1=2;select * from `order` ");
var list3 = db.Ado.SqlQuery<int>(" delete from `order` where 2=15 ");
var list= db.Ado.SqlQuery<Order>("select * from `Order` ");
var list2 = db.Ado.SqlQuery<Order,Order>("select * from `Order` where 1=2;select * from `Order` ");
var list3 = db.Ado.SqlQuery<int>(" delete from `Order` where 2=15 ");
var intValue=db.Ado.SqlQuerySingle<int>("select 1");
db.Ado.ExecuteCommand("delete from `order` where id>1000");
db.Ado.ExecuteCommand("delete from `Order` where id>1000");
//db.Ado.xxx
Console.WriteLine("#### Ado End ####");
}

2
Src/Asp.Net/MySqlConnectorTest/Demo/DemoF_Utilities.cs

@ -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 ####");

8
Src/Asp.Net/MySqlConnectorTest/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 ####");
}

4
Src/Asp.Net/MySqlConnectorTest/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();
}
}

Loading…
Cancel
Save