diff --git a/OrmTest/Demo/Delete.cs b/OrmTest/Demo/Delete.cs new file mode 100644 index 000000000..0dc19f7da --- /dev/null +++ b/OrmTest/Demo/Delete.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest.Demo +{ + class Delete + { + } +} diff --git a/OrmTest/Demo/Insert.cs b/OrmTest/Demo/Insert.cs new file mode 100644 index 000000000..25da9de83 --- /dev/null +++ b/OrmTest/Demo/Insert.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest.Demo +{ + class Insert + { + } +} diff --git a/OrmTest/Demo/Query.cs b/OrmTest/Demo/Query.cs new file mode 100644 index 000000000..1e4b86d4d --- /dev/null +++ b/OrmTest/Demo/Query.cs @@ -0,0 +1,77 @@ +using OrmTest.Models; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest.Demo +{ + public class Query + { + + public static void Init() + { + Easy(); + Page(); + Where(); + Join(); + Funs(); + Select(); + } + + public static void Easy() + { + var db = GetInstance(); + var getAll = db.Queryable().ToList(); + var getByPrimaryKey = db.Queryable().InSingle(2); + var getByWhere = db.Queryable().Where(it => it.Id == 1 || it.Name == "a").ToList(); + var getByFuns = db.Queryable().Where(it => NBORM.IsNullOrEmpty(it.Name)).ToList(); + } + + public static void Page() + { + + } + public static void Where() + { + var db = GetInstance(); + //join + var list = db.Queryable((st, sc) => new object[] { + JoinType.Left,st.SchoolId==sc.Id + }) + .Where(sc => sc.Id == 1) + .Where(st => st.Id == 1) + .Where((st, sc) => st.Id == 1 && sc.Id == 2).ToList(); + + //SELECT [st].[Id],[st].[SchoolId],[st].[Name],[st].[CreateTime] FROM [Student] st + //Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] ) + //WHERE ( [sc].[Id] = @Id0 ) AND ( [st].[Id] = @Id1 ) AND (( [st].[Id] = @Id2 ) AND ( [sc].[Id] = @Id3 )) + } + public static void Join() + { + + } + public static void Funs() + { + + } + public static void Select() + { + + } + + public static SqlSugarClient GetInstance() + { + SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + db.Ado.IsEnableLogEvent = true; + db.Ado.LogEventStarting = (sql, pars) => + { + Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars)); + Console.WriteLine(); + }; + return db; + } + } +} diff --git a/OrmTest/Demo/Update.cs b/OrmTest/Demo/Update.cs new file mode 100644 index 000000000..342713215 --- /dev/null +++ b/OrmTest/Demo/Update.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest.Demo +{ + class Update + { + } +} diff --git a/OrmTest/OrmTest.csproj b/OrmTest/OrmTest.csproj index b805ef971..b7ff42c83 100644 --- a/OrmTest/OrmTest.csproj +++ b/OrmTest/OrmTest.csproj @@ -56,6 +56,10 @@ + + + + @@ -90,9 +94,7 @@ SqlSugar - - - +