From 296842154dfa98393538ec9a479d7e70b2d22666 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 11 Dec 2022 16:33:51 +0800 Subject: [PATCH] Update mysql demo --- Src/Asp.Net/MySqlTest/App.config | 20 +++++++++-- Src/Asp.Net/MySqlTest/Config.cs | 6 ++-- Src/Asp.Net/MySqlTest/Demo/Demo1_Queryable.cs | 6 ++-- .../MySqlTest/Demo/Demo2_Updateable.cs | 4 +-- .../MySqlTest/Demo/Demo5_SqlQueryable.cs | 6 ++-- Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs | 12 +++---- Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs | 2 +- Src/Asp.Net/MySqlTest/MySqlTest.csproj | 35 +++++++++++++++++++ Src/Asp.Net/MySqlTest/packages.config | 12 +++++++ 9 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 Src/Asp.Net/MySqlTest/packages.config diff --git a/Src/Asp.Net/MySqlTest/App.config b/Src/Asp.Net/MySqlTest/App.config index 2d2a12d81..3449815cb 100644 --- a/Src/Asp.Net/MySqlTest/App.config +++ b/Src/Asp.Net/MySqlTest/App.config @@ -1,6 +1,22 @@ - + - + + + + + + + + + + + + + + + + + diff --git a/Src/Asp.Net/MySqlTest/Config.cs b/Src/Asp.Net/MySqlTest/Config.cs index f2f301882..3730a4a0a 100644 --- a/Src/Asp.Net/MySqlTest/Config.cs +++ b/Src/Asp.Net/MySqlTest/Config.cs @@ -16,17 +16,17 @@ namespace OrmTest /// Account have permission to create database /// 用有建库权限的数据库账号 /// - public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql"; + public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=123456;AllowLoadLocalInfile=true"; /// /// Account have permission to create database /// 用有建库权限的数据库账号 /// - public static string ConnectionString2 = "server=localhost;Database=SqlSugar4xTest2;Uid=root;Pwd=haosql"; + public static string ConnectionString2 = "server=localhost;Database=SqlSugar4xTest2;Uid=root;Pwd=123456;AllowLoadLocalInfile=true"; /// /// Account have permission to create database /// 用有建库权限的数据库账号 /// - public static string ConnectionString3 = "server=localhost;Database=SqlSugar4xTest3;Uid=root;Pwd=haosql"; + public static string ConnectionString3 = "server=localhost;Database=SqlSugar4xTest3;Uid=root;Pwd=123456;AllowLoadLocalInfile=true"; /***注意:如果报错:指字关键词不在字典中这说明需要更新MYSQL.DATA驱动到最新,不报错就不需要更新***/ diff --git a/Src/Asp.Net/MySqlTest/Demo/Demo1_Queryable.cs b/Src/Asp.Net/MySqlTest/Demo/Demo1_Queryable.cs index e6078defd..b1c7e1fbe 100644 --- a/Src/Asp.Net/MySqlTest/Demo/Demo1_Queryable.cs +++ b/Src/Asp.Net/MySqlTest/Demo/Demo1_Queryable.cs @@ -198,7 +198,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(); @@ -257,9 +257,9 @@ 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(); + 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 ####"); } diff --git a/Src/Asp.Net/MySqlTest/Demo/Demo2_Updateable.cs b/Src/Asp.Net/MySqlTest/Demo/Demo2_Updateable.cs index 08eec174f..dbddbfcaf 100644 --- a/Src/Asp.Net/MySqlTest/Demo/Demo2_Updateable.cs +++ b/Src/Asp.Net/MySqlTest/Demo/Demo2_Updateable.cs @@ -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/MySqlTest/Demo/Demo5_SqlQueryable.cs b/Src/Asp.Net/MySqlTest/Demo/Demo5_SqlQueryable.cs index 6c904f061..e40cedef8 100644 --- a/Src/Asp.Net/MySqlTest/Demo/Demo5_SqlQueryable.cs +++ b/Src/Asp.Net/MySqlTest/Demo/Demo5_SqlQueryable.cs @@ -22,13 +22,13 @@ namespace OrmTest }); int total = 0; - var list = db.SqlQueryable("select * from `order`").ToPageList(1, 2, ref total); + var list = db.SqlQueryable("select * from `Order`").ToPageList(1, 2, ref total); //by expression - var list2 = db.SqlQueryable("select * from `order`").Where(it => it.Id == 1).ToPageList(1, 2); + var list2 = db.SqlQueryable("select * from `Order`").Where(it => it.Id == 1).ToPageList(1, 2); //by sql - var list3 = db.SqlQueryable("select * from `order`").Where("id=@id", new { id = 1 }).ToPageList(1, 2); + var list3 = db.SqlQueryable("select * from `Order`").Where("id=@id", new { id = 1 }).ToPageList(1, 2); Console.WriteLine("#### SqlQueryable End ####"); } diff --git a/Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs b/Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs index 965c609be..7d373f808 100644 --- a/Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs +++ b/Src/Asp.Net/MySqlTest/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(){ + var dt = db.Ado.GetDataTable("select * from `Order` where @id>0 or name=@name", new List(){ 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("select * from `order` "); - var list2 = db.Ado.SqlQuery("select * from `order` where 1=2;select * from `order` "); - var list3 = db.Ado.SqlQuery(" delete from `order` where 2=15 "); + var list= db.Ado.SqlQuery("select * from `Order` "); + var list2 = db.Ado.SqlQuery("select * from `Order` where 1=2;select * from `Order` "); + var list3 = db.Ado.SqlQuery(" delete from `Order` where 2=15 "); var intValue=db.Ado.SqlQuerySingle("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 ####"); } diff --git a/Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs b/Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs index 4e492035f..920c4d45b 100644 --- a/Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs +++ b/Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs @@ -37,7 +37,7 @@ namespace OrmTest Console.WriteLine(string.Join("," ,list)); }); - var list2= db.Utilities.DataTableToList(db.Ado.GetDataTable("select * from `order`")); + var list2= db.Utilities.DataTableToList(db.Ado.GetDataTable("select * from `Order`")); //more https://github.com/sunkaixuan/SqlSugar/wiki/f.Utilities Console.WriteLine("#### Utilities End ####"); diff --git a/Src/Asp.Net/MySqlTest/MySqlTest.csproj b/Src/Asp.Net/MySqlTest/MySqlTest.csproj index e816e346e..6ad0376a7 100644 --- a/Src/Asp.Net/MySqlTest/MySqlTest.csproj +++ b/Src/Asp.Net/MySqlTest/MySqlTest.csproj @@ -34,15 +34,49 @@ 4 + + ..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll + + + ..\packages\Google.Protobuf.3.19.4\lib\net45\Google.Protobuf.dll + + + ..\packages\K4os.Compression.LZ4.1.2.6\lib\net46\K4os.Compression.LZ4.dll + + + ..\packages\K4os.Compression.LZ4.Streams.1.2.6\lib\net46\K4os.Compression.LZ4.Streams.dll + + + ..\packages\K4os.Hash.xxHash.1.0.6\lib\net46\K4os.Hash.xxHash.dll + + + ..\packages\MySql.Data.8.0.31\lib\net452\MySql.Data.dll + + + ..\packages\System.Buffers.4.5.1\lib\netstandard1.1\System.Buffers.dll + + + + + + ..\packages\System.Memory.4.5.4\lib\netstandard1.1\System.Memory.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + + ..\packages\MySql.Data.8.0.31\lib\net452\ZstdNet.dll + @@ -121,6 +155,7 @@ + diff --git a/Src/Asp.Net/MySqlTest/packages.config b/Src/Asp.Net/MySqlTest/packages.config new file mode 100644 index 000000000..1c5c99520 --- /dev/null +++ b/Src/Asp.Net/MySqlTest/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file