From 360747a2b3996928d574c654459937b53cb141b0 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 20 May 2019 17:58:18 +0800 Subject: [PATCH] - --- .../Demo/Demo0_SqlSugarClient.cs | 6 +++ .../SqlServerTest/Demo/Demo5_SqlQueryable.cs | 37 +++++++++++++++++++ Src/Asp.Net/SqlServerTest/Program.cs | 1 + .../SqlServerTest/SqlServerTest.csproj | 1 + 4 files changed, 45 insertions(+) create mode 100644 Src/Asp.Net/SqlServerTest/Demo/Demo5_SqlQueryable.cs diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs index 57b24cc7c..73686962e 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs @@ -40,9 +40,15 @@ namespace OrmTest } }); + //if no exist create datebase SQLSUGAR4XTEST (bin/database/) + db.DbMaintenance.CreateDatabase(); + //Use db var dt = db.Ado.GetDataTable("select 1"); + //create table OrderDetail + db.CodeFirst.InitTables(typeof(OrderItem)); + db.Insertable(new OrderItem() { OrderId = 1, Price = 0 }).ExecuteCommand(); Console.WriteLine("#### SqlSugarClient End ####"); diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo5_SqlQueryable.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo5_SqlQueryable.cs new file mode 100644 index 000000000..eba7a80d0 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo5_SqlQueryable.cs @@ -0,0 +1,37 @@ +using OrmTest.Models; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class Demo5_SqlQueryable + { + public static void Init() + { + Console.WriteLine(""); + Console.WriteLine("#### SqlQueryable Start ####"); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + DbType = DbType.SqlServer, + ConnectionString = Config.ConnectionString, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true + }); + + int total = 0; + var list = db.SqlQueryable("select * from student").ToPageList(1, 2, ref total); + + + //by expression + var list2 = db.SqlQueryable("select * from student").Where(it => it.Id == 1).ToPageList(1, 2); + //by sql + var list3 = db.SqlQueryable("select * from student").Where("id=@id", new { id = 1 }).ToPageList(1, 2); + + Console.WriteLine("#### SqlQueryable End ####"); + } + } +} diff --git a/Src/Asp.Net/SqlServerTest/Program.cs b/Src/Asp.Net/SqlServerTest/Program.cs index 027bc91bf..a7f79c4b1 100644 --- a/Src/Asp.Net/SqlServerTest/Program.cs +++ b/Src/Asp.Net/SqlServerTest/Program.cs @@ -17,6 +17,7 @@ namespace OrmTest Democ_GobalFilter.Init(); DemoD_DbFirst.Init(); DemoE_CodeFirst.Init(); + Demo5_SqlQueryable.Init(); //Unit test NewUnitTest.Init(); diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 325d26897..bad634e49 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -54,6 +54,7 @@ +