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#>lsgG4egd82Pp`M!qeKk#93&e`3kLCu($oB+e_aI~Bdw?(cdut`lKsu}S`SuV-wM|J~~uo8*7@dd4RC-@Tr(
zN&a`QXKa%H-Rl{flvHmfA@OECi&mJp0P>(cdut`
zlKsu}S`SuV-wM|J~~uo8*7@dd4RC-@Tr(N&a`QXKa%H-Rl{f
zlvHmfA@OECi&mJp0P>(cdut`lKsu}S`SuV-wM|J~~uo8*7@dd4RC-@Tr(N&a`QXKa%H-Rl{flvHmfA@OECi&mJp0P>(cdut`lK@%)JV@4z1)k^dc>@%)JV
V@8FE*N92D8XFNY5|2rA${{jPMR*?Vz
literal 0
HcmV?d00001
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/1_Query.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/1_Query.cs
new file mode 100644
index 000000000..96532db26
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/1_Query.cs
@@ -0,0 +1,348 @@
+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 : DemoBase
+ {
+
+ public static void Init()
+ {
+ Easy();
+ Page();
+ Where();
+ Join();
+ Funs();
+ Select();
+ Ado();
+ Group();
+ Sqlable();
+ Tran();
+ StoredProcedure();
+ Enum();
+ Simple();
+ }
+
+ private static void Simple()
+ {
+ //SqlSugarClient
+ var db = GetInstance();
+ var student1 = db.Queryable().InSingle(1);
+
+ //get SimpleClient
+ var sdb = db.SimpleClient;
+ var student2 = sdb.GetById(1);
+ sdb.DeleteById(1);
+ sdb.Insert(new Student() { Name = "xx" });
+ sdb.Update(it => new Student { Name = "newvalue" }, it => it.Id == 1);//only update name where id=1
+ sdb.Update(new Student() { Name="newavalue" ,Id=1});//update all where id=1
+
+ //SimpleClient Get SqlSugarClient
+ var student3=sdb.FullClient.Queryable().InSingle(1);
+
+ }
+
+ private static void StoredProcedure()
+ {
+ //var db = GetInstance();
+ ////1. no result
+ //db.Ado.UseStoredProcedure(() =>
+ //{
+ // string spName = "sp_help";
+ // var getSpReslut = db.Ado.SqlQueryDynamic(spName, new { objname = "student" });
+ //});
+
+ ////2. has result
+ //var result = db.Ado.UseStoredProcedure(() =>
+ // {
+ // string spName = "sp_help";
+ // return db.Ado.SqlQueryDynamic(spName, new { objname = "student" });
+ // });
+
+ ////2. has output
+ //object outPutValue;
+ //var outputResult = db.Ado.UseStoredProcedure(() =>
+ //{
+ // string spName = "sp_school";
+ // var p1 = new SugarParameter("@p1", "1");
+ // var p2 = new SugarParameter("@p2", null, true);//isOutput=true
+ // var dbResult = db.Ado.SqlQueryDynamic(spName, new SugarParameter[] { p1, p2 });
+ // outPutValue = p2.Value;
+ // return dbResult;
+ //});
+ }
+ private static void Tran()
+ {
+ var db = GetInstance();
+ var x=db.Insertable(new Student() { CreateTime = DateTime.Now, Name = "tran" }).ExecuteCommand();
+ var count1 = db.Queryable().Count();
+ //1. no result
+ var result = db.Ado.UseTran(() =>
+ {
+
+ var beginCount = db.Queryable().ToList();
+ db.Ado.ExecuteCommand("delete from student");
+ var endCount = db.Queryable().Count();
+ throw new Exception("error haha");
+ });
+ var count2 = db.Queryable().Count();
+
+ //2 has result
+ var result2 = db.Ado.UseTran>(() =>
+ {
+ return db.Queryable().ToList();
+ });
+
+ //3 use try
+ try
+ {
+ db.Ado.BeginTran();
+
+ db.Ado.CommitTran();
+ }
+ catch (Exception)
+ {
+ db.Ado.RollbackTran();
+ throw;
+ }
+ }
+ private static void Group()
+ {
+ var db = GetInstance();
+ var list = db.Queryable()
+ .GroupBy(it => it.Name)
+ .GroupBy(it => it.Id).Having(it => SqlFunc.AggregateAvg(it.Id) > 0)
+ .Select(it => new { idAvg = SqlFunc.AggregateAvg(it.Id), name = it.Name }).ToList();
+
+
+ var list2 = db.Queryable()
+ .GroupBy(it => new { it.Id, it.Name }).Having(it => SqlFunc.AggregateAvg(it.Id) > 0)
+ .Select(it => new { idAvg = SqlFunc.AggregateAvg(it.Id), name = it.Name }).ToList();
+
+ // group id,name take first
+ var list3 = db.Queryable()
+ .PartitionBy(it => new { it.Id, it.Name }).Take(1).ToList();
+
+
+ //SQL:
+ //SELECT AVG([Id]) AS[idAvg], [Name] AS[name] FROM[Student] GROUP BY[Name],[Id] HAVING(AVG([Id]) > 0 )
+
+ //SqlFunc.AggregateSum(object thisValue)
+ //SqlFunc.AggregateAvg(TResult thisValue)
+ //SqlFunc.AggregateMin(object thisValue)
+ //SqlFunc.AggregateMax(object thisValue)
+ //SqlFunc.AggregateCount(object thisValue)
+ }
+ private static void Ado()
+ {
+ var db = GetInstance();
+ db.Ado.BeginTran();
+ var t1 = db.Ado.SqlQuery("select 'a'");
+ var t2 = db.Ado.GetInt("select 1");
+ var t3 = db.Ado.GetDataTable("select 1 as id");
+ db.Ado.CommitTran();
+ //more
+ //db.Ado.GetXXX...
+ }
+ public static void Easy()
+ {
+ var db = GetInstance();
+ var getAll = db.Queryable().ToList();
+ var getLike = db.Queryable().Where(it => it.Name.Contains("a")).ToList();
+ var getAllOrder = db.Queryable().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
+ var getId = db.Queryable().Select(it => it.Id).ToList();
+ var getNew = db.Queryable().Where(it => it.Id == 1).Select(it => new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id), it.Name, it.SchoolId }).ToList();
+ var getAllNoLock = db.Queryable().With(SqlWith.NoLock).ToList();
+ var getByPrimaryKey = db.Queryable().InSingle(2);
+ var getSingleOrDefault = db.Queryable().Single();
+ var getFirstOrDefault = db.Queryable().First();
+ var getByWhere = db.Queryable().Where(it => it.Id == 1 || it.Name == "a").ToList();
+ var getByFuns = db.Queryable().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
+ var sum = db.Queryable().Sum(it => it.Id);
+ var isAny = db.Queryable().Where(it => it.Id == -1).Any();
+ var isAny2 = db.Queryable().Any(it => it.Id == -1);
+ var getListByRename = db.Queryable().AS("Student").ToList();
+ var in1 = db.Queryable().In(it => it.Id, new int[] { 1, 2, 3 }).ToList();
+ var in2 = db.Queryable().In(new int[] { 1, 2, 3 }).ToList();
+ int[] array = new int[] { 1, 2 };
+ var in3 = db.Queryable().Where(it => SqlFunc.ContainsArray(array, it.Id)).ToList();
+ var group = db.Queryable().GroupBy(it => it.Id)
+ .Having(it => SqlFunc.AggregateCount(it.Id) > 10)
+ .Select(it => new { id = SqlFunc.AggregateCount(it.Id) }).ToList();
+
+ var between = db.Queryable().Where(it => SqlFunc.Between(it.Id, 1, 20)).ToList();
+
+ var getTodayList = db.Queryable().Where(it => SqlFunc.DateIsSame(it.CreateTime, DateTime.Now)).ToList();
+ }
+ public static void Page()
+ {
+ var db = GetInstance();
+ var pageIndex = 2;
+ var pageSize = 2;
+ var totalCount = 0;
+ //page
+ var page = db.Queryable().OrderBy(it => it.Id).ToPageList(pageIndex, pageSize, ref totalCount);
+
+ //page join
+ var pageJoin = db.Queryable((st, sc) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id
+ }).ToPageList(pageIndex, pageSize, ref totalCount);
+
+ //top 5
+ var top5 = db.Queryable().Take(5).ToList();
+
+ //skip5
+ var skip5 = db.Queryable().Skip(5).ToList();
+ }
+ public static void Where()
+ {
+ var db = GetInstance();
+ //join
+ var list = db.Queryable((st, sc) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id
+ })
+ .Where((st, sc) => sc.Id == 1)
+ .Where((st, sc) => 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 ))
+
+
+ //Where If
+ string name = null;
+ string name2 = "sunkaixuan";
+ var list2 = db.Queryable()
+ .WhereIF(!string.IsNullOrEmpty(name), it => it.Name == name)
+ .WhereIF(!string.IsNullOrEmpty(name2), it => it.Name == name2).ToList();
+ }
+ public static void Join()
+ {
+ var db = GetInstance();
+ //join 2
+ var list = db.Queryable((st, sc) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id
+ })
+ .Where(st => st.Name == "jack").ToList();
+
+ //join 3
+ var list2 = db.Queryable((st, sc, st2) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id,
+ JoinType.Left,st.SchoolId==st2.Id
+ })
+ .Where((st, sc, st2) => st2.Id == 1 || sc.Id == 1 || st.Id == 1).ToList();
+
+ //join return List
+ var list3 = db.Queryable((st, sc) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id
+ }).Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = sc.Id }).ToList();
+
+ //join Order By (order by st.id desc,sc.id desc)
+ var list4 = db.Queryable((st, sc) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id
+ })
+ .OrderBy(st => st.Id, OrderByType.Desc)
+ .OrderBy((st, sc) => sc.Id, OrderByType.Desc)
+ .Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = sc.Id }).ToList();
+
+
+ //join 2
+ var list4_1 = db.Queryable((st, sc) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id&& st.Name == "jack"
+ }).ToList();
+
+
+ //The simple use of Join 2 table
+ var list5 = db.Queryable((st, sc) => st.SchoolId == sc.Id).Select((st,sc)=>new {st.Name,st.Id,schoolName=sc.Name}).ToList();
+
+ //join 3 table
+ var list6 = db.Queryable((st, sc,sc2) => st.SchoolId == sc.Id&&sc.Id==sc2.Id)
+ .Select((st, sc,sc2) => new { st.Name, st.Id, schoolName = sc.Name,schoolName2=sc2.Name }).ToList();
+
+ //join 3 table page
+ var list7= db.Queryable((st, sc, sc2) => st.SchoolId == sc.Id && sc.Id == sc2.Id)
+ .Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1,2);
+
+ //join 3 table page
+ var list8 = db.Queryable((st, sc, sc2) => st.SchoolId == sc.Id && sc.Id == sc2.Id)
+ .OrderBy(st=>st.Id)
+ .Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1, 2);
+ }
+ public static void Funs()
+ {
+ var db = GetInstance();
+ var t1 = db.Queryable().Where(it => SqlFunc.ToLower(it.Name) == SqlFunc.ToLower("JACK")).ToList();
+ //SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WHERE ((LOWER([Name])) = (LOWER(@MethodConst0)) )
+
+ /***More Functions***/
+ //SqlFunc.IsNullOrEmpty(object thisValue)
+ //SqlFunc.ToLower(object thisValue)
+ //SqlFunc.string ToUpper(object thisValue)
+ //SqlFunc.string Trim(object thisValue)
+ //SqlFunc.bool Contains(string thisValue, string parameterValue)
+ //SqlFunc.ContainsArray(object[] thisValue, string parameterValue)
+ //SqlFunc.StartsWith(object thisValue, string parameterValue)
+ //SqlFunc.EndsWith(object thisValue, string parameterValue)
+ //SqlFunc.Equals(object thisValue, object parameterValue)
+ //SqlFunc.DateIsSame(DateTime date1, DateTime date2)
+ //SqlFunc.DateIsSame(DateTime date1, DateTime date2, DateType dataType)
+ //SqlFunc.DateAdd(DateTime date, int addValue, DateType millisecond)
+ //SqlFunc.DateAdd(DateTime date, int addValue)
+ //SqlFunc.DateValue(DateTime date, DateType dataType)
+ //SqlFunc.Between(object value, object start, object end)
+ //SqlFunc.ToInt32(object value)
+ //SqlFunc.ToInt64(object value)
+ //SqlFunc.ToDate(object value)
+ //SqlFunc.ToString(object value)
+ //SqlFunc.ToDecimal(object value)
+ //SqlFunc.ToGuid(object value)
+ //SqlFunc.ToDouble(object value)
+ //SqlFunc.ToBool(object value)
+ //SqlFunc.Substring(object value, int index, int length)
+ //SqlFunc.Replace(object value, string oldChar, string newChar)
+ //SqlFunc.Length(object value) { throw new NotImplementedException(); }
+ //SqlFunc.AggregateSum(object thisValue)
+ //SqlFunc.AggregateAvg(TResult thisValue)
+ //SqlFunc.AggregateMin(object thisValue)
+ //SqlFunc.AggregateMax(object thisValue)
+ //SqlFunc.AggregateCount(object thisValue)
+ }
+ public static void Select()
+ {
+ var db = GetInstance();
+ db.IgnoreColumns.Add("TestId", "Student");
+ var s1 = db.Queryable().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
+ var s2 = db.Queryable().Select(it => new { id = it.Id, w = new { x = it } }).ToList();
+ var s3 = db.Queryable().Select(it => new { newid = it.Id }).ToList();
+ var s4 = db.Queryable().Select(it => new { newid = it.Id, obj = it }).ToList();
+ var s5 = db.Queryable().Select(it => new ViewModelStudent2 { Student = it, Name = it.Name }).ToList();
+ var s6 = db.Queryable((st, sc) => new object[] {
+ JoinType.Left,st.SchoolId==sc.Id
+ })
+ .OrderBy(st => st.Id, OrderByType.Desc)
+ .OrderBy((st, sc) => sc.Id, OrderByType.Desc)
+ .Select((st, sc) => new { Name = st.Name, SchoolId = sc.Id }).ToList();
+ }
+ private static void Sqlable()
+ {
+ var db = GetInstance();
+ var join3 = db.Queryable("Student", "st")
+ .AddJoinInfo("School", "sh", "sh.id=st.schoolid")
+ .Where("st.id>@id")
+ .AddParameters(new { id = 1 })
+ .Select("st.*").ToList();
+ //SELECT st.* FROM [Student] st Left JOIN `School` sh ON sh.id=st.schoolid WHERE st.id>@id
+ }
+ private static void Enum()
+ {
+ var db = GetInstance();
+ var list = db.Queryable().AS("Student").Where(it => it.SchoolId == SchoolEnum.HarvardUniversity).ToList();
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/2_Update.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/2_Update.cs
new file mode 100644
index 000000000..12407ae12
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/2_Update.cs
@@ -0,0 +1,63 @@
+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 Update : DemoBase
+ {
+ public static void Init()
+ {
+ var db = GetInstance();
+ var updateObj = new Student() { Id = 1, Name = "jack", SchoolId = 0, CreateTime = Convert.ToDateTime("2017-05-21 09:56:12.610") };
+ var updateObjs = new List() { updateObj, new Student() { Id = 2, Name = "sun", SchoolId = 0 } }.ToArray();
+ db.IgnoreColumns.Add("TestId", "Student");
+ //db.MappingColumns.Add("id","dbid", "Student");
+
+
+ //update reutrn Update Count
+ var t1 = db.Updateable(updateObj).ExecuteCommand();
+
+ //Only update Name
+ var t3 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name }).ExecuteCommand();
+ var t3_1 = db.Updateable(updateObj).UpdateColumns(it => it=="Name").ExecuteCommand();
+
+
+ //Ignore Name and TestId
+ var t4 = db.Updateable(updateObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteCommand();
+
+ //Ignore Name and TestId
+ var t5 = db.Updateable(updateObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ExecuteCommand();
+
+
+ //Use Lock
+ var t6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ExecuteCommand();
+
+ //update List
+ // var t7 = db.Updateable(updateObjs).ExecuteCommand();
+
+ //Re Set Value
+ var t8 = db.Updateable(updateObj)
+ .ReSetValue(it => it.Name == (it.Name + 1)).ExecuteCommand();
+
+ //Where By Expression
+ var t9 = db.Updateable(updateObj).Where(it => it.Id == 1).ExecuteCommand();
+
+ //Update By Expression Where By Expression
+ var t10 = db.Updateable()
+ .UpdateColumns(it => new Student() { Name = "a", CreateTime = DateTime.Now })
+ .Where(it => it.Id == 11).ExecuteCommand();
+
+ //Rename
+ db.Updateable().AS("Student").UpdateColumns(it => new School() { Name = "jack" }).Where(it => it.Id == 1).ExecuteCommand();
+ //Update Student set Name='jack' Where Id=1
+
+ //Column is null no update
+ db.Updateable(updateObj).Where(true).ExecuteCommand();
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/3_Insert.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/3_Insert.cs
new file mode 100644
index 000000000..7ec172b12
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/3_Insert.cs
@@ -0,0 +1,58 @@
+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 Insert:DemoBase
+ {
+ public static void Init()
+ {
+ var db = GetInstance();
+ db.IgnoreColumns.Add("TestId", "Student");
+
+ var insertObj = new Student() { Name = "jack", CreateTime = Convert.ToDateTime("2010-1-1"), SchoolId = 1 };
+
+ //Insert reutrn Insert Count
+ var t2 = db.Insertable(insertObj).ExecuteCommand();
+
+ //Insert reutrn Identity Value
+ var t3 = db.Insertable(insertObj).ExecuteReturnIdentity();
+
+
+ //Only insert Name and SchoolId
+ var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReturnIdentity();
+ var t4_1 = db.Insertable(insertObj).InsertColumns(it => it=="Name"||it== "SchoolId").ExecuteReturnIdentity();
+
+
+ //Ignore TestId
+ var t5 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteReturnIdentity();
+
+
+ //Ignore TestId
+ var t6 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReturnIdentity();
+
+
+ //Use Lock
+ var t8 = db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
+
+
+ var insertObj2 = new Student() { Name = null, CreateTime = Convert.ToDateTime("2010-1-1") };
+ var t9 = db.Insertable(insertObj2).Where(true/* Is insert null */, false/*off identity*/).ExecuteCommand();
+
+ //Insert List
+ var insertObjs = new List();
+ for (int i = 0; i < 1000; i++)
+ {
+ insertObjs.Add(new Student() { Name = "name" + i });
+ }
+ var t10 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).ExecuteCommand();
+
+ var t11 = db.Insertable(insertObjs.ToArray()).ExecuteCommand();
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/4_Delete.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/4_Delete.cs
new file mode 100644
index 000000000..960434203
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/4_Delete.cs
@@ -0,0 +1,33 @@
+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 Delete:DemoBase
+ {
+ public static void Init()
+ {
+ var db = GetInstance();
+ //by entity
+ var t1 = db.Deleteable().Where(new Student() { Id = 1 }).ExecuteCommand();
+
+ //use lock
+ var t2 = db.Deleteable().With(SqlWith.RowLock).ExecuteCommand();
+
+
+ //by primary key
+ var t3 = db.Deleteable().In(1).ExecuteCommand();
+
+ //by primary key array
+ var t4 = db.Deleteable().In(new int[] { 1, 2 }).ExecuteCommand();
+
+ //by expression
+ var t5 = db.Deleteable().Where(it => it.Id == 1).ExecuteCommand();
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/5_CodeFirst.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/5_CodeFirst.cs
new file mode 100644
index 000000000..b76568f6e
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/5_CodeFirst.cs
@@ -0,0 +1,52 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Demo
+{
+ public class CodeTable
+ {
+
+ [SugarColumn(IsNullable =false ,IsPrimaryKey =true,IsIdentity =true)]
+ public int Id { get; set; }
+ [SugarColumn(Length = 21,OldColumnName = "Name2")]
+ public string Name{ get; set; }
+ [SugarColumn(IsNullable = true,Length =11)]
+ public string IsOk { get; set; }
+ public Guid Guid { get; set; }
+ public decimal Decimal { get; set; }
+ [SugarColumn(IsNullable = true)]
+ public DateTime? DateTime { get; set; }
+ [SugarColumn(IsNullable = true,OldColumnName = "Dob")]
+ public double? Dob2 { get; set; }
+ [SugarColumn(Length =10)]
+ public string A { get; set; }
+ }
+ public class CodeTable2 {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ [SugarColumn(IsIgnore =true)]
+ public string TestId { get; set; }
+ }
+ public class CodeFirst : DemoBase
+ {
+ public static void Init()
+ {
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = Config.ConnectionString,
+ DbType = DbType.Sqlite,
+ IsAutoCloseConnection = true,
+ InitKeyType = InitKeyType.Attribute
+ });
+
+ //Backup table
+ //db.CodeFirst.BackupTable().InitTables(typeof(CodeTable),typeof(CodeTable2));
+
+ //No backup table
+ db.CodeFirst.InitTables(typeof(CodeTable),typeof(CodeTable2));
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/5_DbFirst.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/5_DbFirst.cs
new file mode 100644
index 000000000..eea77d03b
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/5_DbFirst.cs
@@ -0,0 +1,72 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Demo
+{
+ public class DbFirst : DemoBase
+ {
+ public static void Init()
+ {
+ var db = GetInstance();
+ //Create all class
+ db.DbFirst.CreateClassFile("c:\\DemoSqlite\\1");
+
+ //Create student calsss
+ db.DbFirst.Where("Student").CreateClassFile("c:\\DemoSqlite\\2");
+ //Where(array)
+
+ //Mapping name
+ db.MappingTables.Add("ClassStudent", "Student");
+ db.MappingColumns.Add("NewId", "Id", "ClassStudent");
+ db.DbFirst.Where("Student").CreateClassFile("c:\\DemoSqlite\\3");
+
+ //Remove mapping
+ db.MappingTables.Clear();
+
+ //Create class with default value
+ db.DbFirst.IsCreateDefaultValue().CreateClassFile("c:\\DemoSqlite\\4", "Demo.Models");
+
+
+ //Mapping and Attribute
+ db.MappingTables.Add("ClassStudent", "Student");
+ db.MappingColumns.Add("NewId", "Id", "ClassStudent");
+ db.DbFirst.IsCreateAttribute().Where("Student").CreateClassFile("c:\\DemoSqlite\\5");
+
+
+ //Remove mapping
+ db.MappingTables.Clear();
+ db.MappingColumns.Clear();
+
+ //Custom format,Change old to new
+ db.DbFirst.
+ SettingClassTemplate(old =>
+ {
+ return old;
+ })
+ .SettingNamespaceTemplate(old =>
+ {
+ return old;
+ })
+ .SettingPropertyDescriptionTemplate(old =>
+ {
+ return @" ///
+ /// Desc_New:{PropertyDescription}
+ /// Default_New:{DefaultValue}
+ /// Nullable_New:{IsNullable}
+ /// ";
+ })
+ .SettingPropertyTemplate(old =>
+ {
+ return old;
+ })
+ .SettingConstructorTemplate(old =>
+ {
+ return old;
+ })
+ .CreateClassFile("c:\\DemoSqlite\\6");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/6_ComplexModel.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/6_ComplexModel.cs
new file mode 100644
index 000000000..5ca494f05
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/6_ComplexModel.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+using OrmTest.Demo;
+
+namespace OrmTest.Demo
+{
+ public class ComplexModel : DemoBase
+ {
+ public static void Init()
+ {
+ var db = GetInstance();
+ var students = db.Queryable().ToList();
+ if (students != null)
+ {
+ foreach (var item in students)
+ {
+ Console.WriteLine(item.SchoolName);
+ if (item.SchoolSingle != null)
+ {
+ Console.WriteLine(item.SchoolSingle.Name);
+ }
+ if (item.SchoolList != null)
+ {
+ Console.WriteLine(item.SchoolList.Count);
+ }
+ }
+ }
+ }
+ }
+
+ [SugarTable("Student")]
+ public class CMStudent : ModelContext
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public int SchoolId { get; set; }
+
+ [SugarColumn(IsIgnore = true)]
+ public string SchoolName
+ {
+ get
+ {
+ if (this.SchoolSingle != null)
+ return this.SchoolSingle.Name;
+ else
+ return null;
+ }
+ }
+
+ [SugarColumn(IsIgnore = true)]
+ public CMSchool SchoolSingle
+ {
+ get
+ {
+ return base.CreateMapping().Single(it => it.Id == this.SchoolId);
+ }
+ }
+
+ [SugarColumn(IsIgnore = true)]
+ public List SchoolList
+ {
+ get
+ {
+ return base.CreateMapping().Where(it => it.Id == this.SchoolId).ToList();
+ }
+ }
+ }
+
+ [SugarTable("School")]
+ public class CMSchool
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/7_Filter.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/7_Filter.cs
new file mode 100644
index 000000000..cbaf45bef
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/7_Filter.cs
@@ -0,0 +1,72 @@
+using OrmTest.Demo;
+using OrmTest.Models;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Demo
+{
+ public class Filter : DemoBase
+ {
+ public static void Init()
+ {
+
+
+ //gobal filter
+ var db = GetInstance1();
+
+ var sql = db.Queryable().ToSql();
+ //SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE isDelete=0
+
+ var sql2 = db.Queryable((f, s) => new object[] { JoinType.Left, f.SchoolId == s.Id }).ToSql();
+ //SELECT[f].[ID],[f].[SchoolId],[f].[Name],[f].[CreateTime]
+ //FROM[STudent] f Left JOIN `School` s ON([f].[SchoolId] = [s].[Id]) WHERE f.isDelete=0
+
+
+ //Specify name filter
+ var sql3 = db.Queryable().Filter("query1").ToSql();
+ //SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE WHERE id>@id AND isDelete=0
+
+
+ //Specify key filter and disabled global filter
+ string key = "query1";
+ var sql4 = db.Queryable().Filter(key,true).ToSql();
+ //SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE WHERE id>@id
+
+ }
+
+ public static SqlSugarClient GetInstance1()
+ {
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
+ db.QueryFilter
+ .Add(new SqlFilterItem()
+ {
+ FilterValue = filterDb =>
+ {
+ return new SqlFilterResult() { Sql = " isDelete=0" };
+ },
+ IsJoinQuery = false
+ }).Add(new SqlFilterItem()
+ {
+ FilterValue = filterDb =>
+ {
+ return new SqlFilterResult() { Sql = " f.isDelete=0" };
+ },
+ IsJoinQuery = true
+ })
+ .Add(new SqlFilterItem()
+ {
+ FilterName = "query1",
+ FilterValue = filterDb =>
+ {
+ return new SqlFilterResult() { Sql = " id>@id", Parameters = new { id = 1 } };
+ },
+ IsJoinQuery = false
+ });
+ return db;
+ }
+ }
+
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/8_JoinSql.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/8_JoinSql.cs
new file mode 100644
index 000000000..78adb85b8
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/8_JoinSql.cs
@@ -0,0 +1,51 @@
+using OrmTest.Demo;
+using OrmTest.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Demo
+{
+ ///
+ /// Secure string operations
+ ///
+ public class JoinSql : DemoBase
+ {
+ public static void Init()
+ {
+ Where();
+ OrderBy();
+ }
+
+ private static void Where()
+ {
+ var db = GetInstance();
+ //Parameterized processing
+ string value = "'jack';drop table Student";
+ var list = db.Queryable().Where("name=@name", new { name = value }).ToList();
+ //Nothing happened
+ }
+
+ private static void OrderBy()
+ {
+ var db = GetInstance();
+ //propertyName is valid
+ string propertyName = "Id";
+ string dbColumnName = db.EntityProvider.GetDbColumnName(propertyName);
+ var list = db.Queryable().OrderBy(dbColumnName).ToList();
+
+ //propertyName is invalid
+ try
+ {
+ propertyName = "Id'";
+ dbColumnName = db.EntityProvider.GetDbColumnName(propertyName);
+ var list2 = db.Queryable().OrderBy(dbColumnName).ToList();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ }
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/DemoBase.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/DemoBase.cs
new file mode 100644
index 000000000..eb8ab2f53
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Demos/DemoBase.cs
@@ -0,0 +1,23 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Demo
+{
+ public class DemoBase
+ {
+ public static SqlSugarClient GetInstance()
+ {
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Sqlite, 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/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/DataTestInfo.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/DataTestInfo.cs
new file mode 100644
index 000000000..935aefaff
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/DataTestInfo.cs
@@ -0,0 +1,135 @@
+using System;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Models
+{
+ ///
+ ///
+ ///
+ public class DataTestInfo
+ {
+ public DataTestInfo(){
+
+ }
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public int Int1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? Int2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public string String {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public decimal Decimal1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public decimal? Decimal2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public DateTime Datetime1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime? Datetime2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public byte[] Image1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public byte[] Image2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public Guid Guid1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public Guid? Guid2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public decimal Money1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public decimal? Money2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public byte[] Varbinary1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public byte[] Varbinary2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public double Float1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public double? Float2 {get;set;}
+
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/DataTestInfo2.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/DataTestInfo2.cs
new file mode 100644
index 000000000..8f425a4c1
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/DataTestInfo2.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Models
+{
+ ///
+ ///
+ ///
+ public class DataTestInfo2
+ {
+ public DataTestInfo2(){
+
+ }
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public Guid PK {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:False
+ ///
+ public bool Bool1 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public bool? Bool2 {get;set;}
+
+ ///
+ /// Desc:
+ /// Default:
+ /// Nullable:True
+ ///
+ public string Text1 {get;set;}
+
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/Enum.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/Enum.cs
new file mode 100644
index 000000000..09102a410
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/Enum.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.Models
+{
+ public enum SchoolEnum
+ {
+ HarvardUniversity = 0,
+ UniversityOfOxford = 1
+ }
+ public class StudentEnum
+ {
+ public int Id { get; set; }
+ public SchoolEnum SchoolId { get; set; }
+ public string Name { get; set; }
+ public DateTime? CreateTime { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore =true)]
+ public int TestId { get; set; }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/School.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/School.cs
new file mode 100644
index 000000000..4373f3feb
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/School.cs
@@ -0,0 +1,17 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest.Models
+{
+ public class School
+ {
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/Student.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/Student.cs
new file mode 100644
index 000000000..421b87bcf
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/Student.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+using System.Linq.Expressions;
+
+namespace OrmTest.Models
+{
+ [SugarTable("STudent")]
+ public class Student
+ {
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "ID")]
+ public int Id { get; set; }
+ public int? SchoolId { get; set; }
+ public string Name { get; set; }
+ public DateTime? CreateTime { get; set; }
+ [SugarColumn(IsIgnore=true)]
+ public int TestId { get; set; }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/ViewModelStudent.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/ViewModelStudent.cs
new file mode 100644
index 000000000..6705f3dcb
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Models/ViewModelStudent.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest.Models
+{
+ public class ViewModelStudent:Student
+ {
+
+ }
+ public class ViewModelStudent2
+ {
+ public string Name { get; set; }
+ public Student Student { get; set; }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/PerformanceTesting/PerformanceBase.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/PerformanceTesting/PerformanceBase.cs
new file mode 100644
index 000000000..cba502561
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/PerformanceTesting/PerformanceBase.cs
@@ -0,0 +1,30 @@
+using SyntacticSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest.PerformanceTesting
+{
+ public class PerformanceBase
+ {
+ public int count = 100;
+ public void Execute(string title, Action fun)
+ {
+ PerformanceTest ptef = new PerformanceTest();
+ ptef.SetCount(count);//执行count次
+ ptef.Execute(
+ i =>
+ {
+ fun();
+
+ },
+ res =>
+ {
+ Console.WriteLine(string.Format("Execute {0} time,{1}{2}", count, title, res));
+ });
+
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/PerformanceTesting/SqlSugarPerformance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/PerformanceTesting/SqlSugarPerformance.cs
new file mode 100644
index 000000000..686fa65c7
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/PerformanceTesting/SqlSugarPerformance.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+using OrmTest.Models;
+
+namespace OrmTest.PerformanceTesting
+{
+ public class SqlSugarPerformance : PerformanceBase
+ {
+ public SqlSugarPerformance(int eachCount)
+ {
+ this.count = eachCount;
+ }
+ public void Select()
+ {
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = Config.ConnectionString,
+ DbType = DbType.Sqlite,
+ IsAutoCloseConnection = false
+ });
+ db.IgnoreColumns.Add("TestId", "Student");
+ db.Queryable().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
+ base.Execute("sqlsuagr", () =>
+ {
+ var test = db.Queryable().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
+ });
+ db.Close();
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Program.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Program.cs
new file mode 100644
index 000000000..fdd5e1d2c
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/Program.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Linq.Expressions;
+using SqlSugar;
+using OrmTest.Models;
+using System.Data.SqlClient;
+using OrmTest.UnitTest;
+using OrmTest.PerformanceTesting;
+
+namespace OrmTest
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+
+ /***SQLITE CORE case sensitive, Unit comment dropped***/
+
+ ///***Unit Test***/
+ new Field(1).Init();
+ new Where(1).Init();
+ new Method(1).Init();
+ new JoinQuery(1).Init();
+ new SingleQuery(1).Init();
+ new SelectQuery(1).Init();
+ new AutoClose(1).Init();
+ new Insert(1).Init();
+ new Delete(1).Init();
+ new Update(1).Init();
+ new Mapping(1).Init();
+ new DataTest(1).Init();
+
+ /***Performance Test***/
+ new SqlSugarPerformance(100).Select();
+
+ /***Demo***/
+ OrmTest.Demo.Query.Init();
+ OrmTest.Demo.Insert.Init();
+ OrmTest.Demo.Delete.Init();
+ OrmTest.Demo.Update.Init();
+ OrmTest.Demo.DbFirst.Init();
+ OrmTest.Demo.JoinSql.Init();
+ OrmTest.Demo.Filter.Init();
+ OrmTest.Demo.ComplexModel.Init();
+ OrmTest.Demo.CodeFirst.Init();
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/SqliteTest.csproj b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/SqliteTest.csproj
new file mode 100644
index 000000000..c2b9b36c5
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/SqliteTest.csproj
@@ -0,0 +1,12 @@
+
+
+
+ Exe
+ netcoreapp2.0
+
+
+
+
+
+
+
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/DataTest.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/DataTest.cs
new file mode 100644
index 000000000..87f3b32e4
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/DataTest.cs
@@ -0,0 +1,79 @@
+using OrmTest.Models;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest.UnitTest
+{
+ public class DataTest : UnitTestBase
+ {
+ private DataTest() { }
+ public DataTest(int eachCount)
+ {
+ this.Count = eachCount;
+ }
+
+ public void Init()
+ {
+ var guid = Guid.Parse("d8268a7e-a2d1-4329-9990-9bd801292415");
+ var db = GetInstance();
+ db.DbMaintenance.TruncateTable("DataTestInfo");
+ var insertObject = new DataTestInfo()
+ {
+ Datetime1 = DateTime.Now,
+ Datetime2 = DateTime.Now,
+ Decimal1 = 1,
+ Decimal2 = 2,
+ Float1 = 3,
+ Float2 = 4,
+ Guid1 = guid,
+ Guid2 = guid,
+ Image1 = new byte[] { 1, 2 },
+ Image2 = new byte[] { 2, 3 },
+ Int2 = 6,
+ Money1 = 7,
+ Money2 = 8,
+ Varbinary1 = new byte[] { 4, 5 },
+ Varbinary2 = null,
+ String = "string"
+ };
+ var id = db.Insertable(insertObject).ExecuteReturnIdentity();
+ var data = db.Queryable().InSingle(id);
+ if (
+ insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") ||
+ insertObject.Decimal1 != data.Decimal1 ||
+ insertObject.Float1 != data.Float1 ||
+ insertObject.Float2 != data.Float2 ||
+ insertObject.Int2 != data.Int2 ||
+ insertObject.Money1 != data.Money1 ||
+ insertObject.Guid2!=data.Guid2||
+ string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
+ insertObject.String != data.String)
+ {
+ throw new Exception("DataTest Error");
+ }
+ data.Float1= data.Float1+1;
+ db.Updateable(data).ExecuteCommand();
+ data = db.Queryable().InSingle(id);
+ if (
+ insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") ||
+ insertObject.Decimal1 != data.Decimal1 ||
+ (insertObject.Float1+1) != data.Float1 ||
+ insertObject.Float2 != data.Float2 ||
+ insertObject.Int2 != data.Int2 ||
+ insertObject.Money1 != data.Money1 ||
+ string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
+ insertObject.String != data.String)
+ {
+ throw new Exception("DataTest Error");
+ }
+ }
+ public SqlSugarClient GetInstance()
+ {
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Sqlite, IsAutoCloseConnection = true });
+ return db;
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/Delete.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/Delete.cs
new file mode 100644
index 000000000..ac61367cd
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/Delete.cs
@@ -0,0 +1,67 @@
+using OrmTest.Models;
+using OrmTest.UnitTest;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Delete : UnitTestBase
+ {
+ private Delete() { }
+ public Delete(int eachCount)
+ {
+ this.Count = eachCount;
+ }
+
+ public void Init()
+ {
+ var db = GetInstance();
+ //by entity
+ var t1= db.Deleteable().Where(new Student() { Id = 1 }).ToSql();
+ base.Check(@"DELETE FROM `STudent` WHERE `Id` IN ('1') ",
+ null,
+ t1.Key,
+ null, "Delte t1 error"
+ );
+ //use lock
+ var t2 = db.Deleteable().With(SqlWith.RowLock).ToSql();
+ base.Check(@"DELETE FROM `STudent`",
+ null,
+ t2.Key,
+ null, "Delte t2 error"
+ );
+
+ //by primary key
+ var t3 = db.Deleteable().In(1).ToSql();
+ base.Check(@"DELETE FROM `STudent` WHERE `Id` IN ('1') ",
+ null,
+ t3.Key,
+ null, "Delte tt error"
+ );
+ //by primary key array
+ var t4 = db.Deleteable().In(new int[] { 1,2}).ToSql();
+ base.Check(@"DELETE FROM `STudent` WHERE `Id` IN ('1','2') ", null, t4.Key, null, "Update t4 error");
+
+ //by expression
+ var t5 = db.Deleteable().Where(it=>it.Id==1).ToSql();
+ base.Check(@"DELETE FROM `STudent` WHERE ( `ID` = @Id0 ) ", new List() {
+ new SugarParameter("@Id0",1)
+ }, t5.Key, t5.Value, "Delte t5 error");
+
+ var t6 = db.Deleteable().Where("id=@id",new { id=1}).ToSql();
+ base.Check(@"DELETE FROM `STudent` WHERE id=@id", new List() {
+ new SugarParameter("@id",1)
+ }, t6.Key, t6.Value, "Delte t6 error");
+ }
+
+ public SqlSugarClient GetInstance()
+ {
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Sqlite, IsAutoCloseConnection = true });
+ return db;
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/ExpressionTest/Field.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/ExpressionTest/Field.cs
new file mode 100644
index 000000000..1a1080346
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/ExpressionTest/Field.cs
@@ -0,0 +1,51 @@
+using OrmTest.Models;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest.UnitTest
+{
+ public class Field : UnitTestBase
+ {
+ private Field() { }
+ public Field(int eachCount)
+ {
+ this.Count = eachCount;
+ }
+ internal void Init()
+ {
+ base.Begin();
+ for (int i = 0; i < base.Count; i++)
+ {
+ FieldSingle();
+ FieldMultiple();
+ }
+ base.End("Filed Test");
+ }
+ private void FieldSingle()
+ {
+ Expression> exp = it => it.Name;
+ ExpressionContext expContext = GetContext();
+ expContext.Resolve(exp, ResolveExpressType.FieldSingle);
+ var selectorValue = expContext.Result.GetString();
+ Check(selectorValue, null, expContext.GetTranslationColumnName("Name"), null, "FieldSingle error");
+ }
+ private void FieldMultiple()
+ {
+ Expression> exp = it => it.Name;
+ ExpressionContext expContext = GetContext();
+ expContext.Resolve(exp, ResolveExpressType.FieldMultiple);
+ var selectorValue = expContext.Result.GetString();
+ Check(selectorValue, null, expContext.GetTranslationColumnName("it.Name"), null, "FieldMultiple error");
+ }
+
+ public ExpressionContext GetContext()
+ {
+ return new MySqlExpressionContext();//可以更换
+ }
+ }
+}
diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/ExpressionTest/Method.cs b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/ExpressionTest/Method.cs
new file mode 100644
index 000000000..7bb81f322
--- /dev/null
+++ b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/UnitTest/ExpressionTest/Method.cs
@@ -0,0 +1,610 @@
+using OrmTest.Models;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest.UnitTest
+{
+ public class Method : UnitTestBase
+ {
+ private Method() { }
+ public Method(int eachCount)
+ {
+ this.Count = eachCount;
+ }
+ internal void Init()
+ {
+ base.Begin();
+ for (int i = 0; i < base.Count; i++)
+ {
+
+ //Native methods
+ ExtendContainsArray();
+ ConvetToString();
+ ExtendToString();
+ ExtendSubstring();
+ ExtendDate();
+
+ //SqlFun methods
+ IIF();
+ IIF2();
+ #region StringIsNullOrEmpty
+ HasValue();
+ HasNumber();
+ StringIsNullOrEmpty();
+ StringIsNullOrEmpty2();
+ StringIsNullOrEmpty3();
+ StringIsNullOrEmpty4();
+ StringIsNullOrEmpty5();
+ #endregion
+ ToUpper();
+ ToLower();
+ Trim();
+ Contains();
+ Contains2();
+ ContainsArray();
+ StartsWith();
+ EndsWith();
+ Between();
+ Equals();
+ Equals_2();
+ DateIsSameByDay();
+ DateIsSameByType();
+ DateAddDay();
+ DateAddByType();
+ DateValue();
+ ToInt32();
+ ToInt64();
+ ToDate();
+ Tostring();
+ ToDecimal();
+ ToGuid();
+ ToDouble();
+ ToBool();
+ Substring();
+ Replace();
+ Length();
+ }
+ base.End("Method Test");
+ }
+
+ private void ExtendToString()
+ {
+ Expression> exp = it => it.Id.ToString() == "a";
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(`Id` AS TEXT) = @Const0 )", new List() {
+ new SugarParameter("@Const0","a")
+ }, "ExtendToString error");
+ }
+
+ private void ConvetToString()
+ {
+ Expression> exp = it => Convert.ToString(it.Id) == "a";
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(`Id` AS TEXT) = @Const0 )", new List() {
+ new SugarParameter("@Const0","a")
+ }, "ConvetToString error");
+ }
+
+
+ private void Length()
+ {
+ Expression> exp = it => SqlFunc.Length("aaaa") > 1;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(LENGTH(@MethodConst0) > @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","aaaa"),new SugarParameter("@Const1",1)
+ }, "Length error");
+ }
+
+ private void Replace()
+ {
+ var x2 = Guid.NewGuid();
+ Expression> exp = it => SqlFunc.Replace("aaaa", "a", "1") == "a";
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(REPLACE(@MethodConst0,@MethodConst1,@MethodConst2) = @Const3 )", new List() {
+ new SugarParameter("@MethodConst0","aaaa"), new SugarParameter("@MethodConst1","a") , new SugarParameter("@MethodConst2","1"),new SugarParameter("@Const3","a")
+ }, "Replace error");
+ }
+
+ private void Substring()
+ {
+ var x2 = Guid.NewGuid();
+ Expression> exp = it => SqlFunc.Substring("aaaa", 0, 2) == "a";
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(SUBSTRING(@MethodConst0,1 + @MethodConst1,@MethodConst2) = @Const3 )", new List() {
+ new SugarParameter("@MethodConst0","aaaa"), new SugarParameter("@MethodConst1",0) , new SugarParameter("@MethodConst2",2),new SugarParameter("@Const3","a")
+ }, "Substring error");
+ }
+ private void ExtendSubstring()
+ {
+ var x2 = Guid.NewGuid();
+ Expression> exp = it =>"aaaa".Substring(0, 2)== "a";
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(SUBSTRING(@MethodConst0,1 + @MethodConst1,@MethodConst2) = @Const3 )", new List() {
+ new SugarParameter("@MethodConst0","aaaa"), new SugarParameter("@MethodConst1",0) , new SugarParameter("@MethodConst2",2),new SugarParameter("@Const3","a")
+ }, "Substring error");
+ }
+
+
+ private void ToBool()
+ {
+ var x2 = Guid.NewGuid();
+ Expression> exp = it => SqlFunc.ToBool("true") == true;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(@MethodConst0 AS SIGNED) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","true"),new SugarParameter("@Const1",(bool)true)
+ }, "ToBool error");
+ }
+
+ private void ToDouble()
+ {
+ var x2 = Guid.NewGuid();
+ Expression> exp = it => SqlFunc.ToDouble("2") == 2;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(@MethodConst0 AS DECIMAL(18,4)) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","2"),new SugarParameter("@Const1",(Double)2)
+ }, "ToDouble error");
+ }
+
+ private void ToGuid()
+ {
+ var x2 = Guid.NewGuid();
+ Expression> exp = it => SqlFunc.ToGuid("A94027A3-476E-478D-8228-F4054394B874") == x2;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(@MethodConst0 AS TEXT) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","A94027A3-476E-478D-8228-F4054394B874"),new SugarParameter("@Const1",x2)
+ }, "ToGuid error");
+ }
+
+ private void ToDecimal()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.ToDecimal("22") == 1;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(@MethodConst0 AS DECIMAL(18,4)) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","22"),new SugarParameter("@Const1",(decimal)1)
+ }, "ToDecimal error");
+ }
+
+ private void Tostring()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.ToString("2015-1-1") == "a";
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(@MethodConst0 AS TEXT) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1","a")
+ }, "Tostring error");
+ }
+
+ private void ToDate()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.ToDate("2015-1-1") == x2;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(DATETIME(@MethodConst0) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
+ }, "ToDate error");
+ }
+ private void ExtendDate()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => Convert.ToDateTime("2015-1-1") == x2;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(DATETIME(@MethodConst0) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
+ }, "ExtendDate error");
+ }
+
+ private void ToInt64()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.ToInt64("3") == 1;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(@MethodConst0 AS INTEGER) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",(Int64)1)
+ }, "ToInt64 error");
+ }
+
+ private void ToInt32()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.ToInt32("3") == 1;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(@MethodConst0 AS INTEGER) = @Const1 )", new List() {
+ new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",1)
+ }, "ToInt32 error");
+ }
+
+ private void DateValue()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.DateValue(x2, DateType.Year) == 1;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(CAST(STRFTIME('%Y', DATETIME(DATETIME(@MethodConst0), 'LOCALTIME')) AS INTEGER) = @Const2 )", new List() {
+ new SugarParameter("@MethodConst0",x2),new SugarParameter("@Const2",1)
+ }, "DateValue error");
+ }
+
+ private void StartsWith()
+ {
+ Expression> exp = it => SqlFunc.StartsWith(it.Name, "a");
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " (`Name` like @MethodConst0||'%') ", new List() {
+ new SugarParameter("@MethodConst0","a")
+ }, "StartsWith error");
+ }
+ private void EndsWith()
+ {
+ Expression> exp = it => SqlFunc.EndsWith(it.Name, "a");
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " (`Name` like '%'||@MethodConst0) ", new List() {
+ new SugarParameter("@MethodConst0","a")
+ }, "EndsWith");
+ }
+ private void Between()
+ {
+ Expression> exp = it => SqlFunc.Between(it.Name, 1, 2);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " (`Name` BETWEEN @MethodConst0 AND @MethodConst1) ", new List() {
+ new SugarParameter("@MethodConst0",1),new SugarParameter("@MethodConst1",2),
+ }, "Between error");
+ }
+
+ private void DateAddByType()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.DateAdd(x2, 11, DateType.Minute) == x2;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(DATETIME(DATETIME(@MethodConst0), '+11 Minutes') = @Const3 )", new List() {
+ new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2)
+ }, "DateAddByType error");
+ }
+ private void DateAddDay()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.DateAdd(x2, 1) == x2;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "(DATE(DATETIME(@MethodConst0), '+1 days') = @Const2 )", new List() {
+ new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",1),new SugarParameter("@Const2",x2)
+ }, "DateAddDay error");
+ }
+
+ private void DateIsSameByType()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.DateIsSame(x2, x2, DateType.Millisecond);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " Cast((JulianDay(@MethodConst0) - JulianDay(@MethodConst1)) *86400000 As INTEGER)", new List() {
+ new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2)
+ }, "DateIsSameByType error");
+ }
+ private void DateIsSameByDay()
+ {
+ var x2 = DateTime.Now;
+ Expression> exp = it => SqlFunc.DateIsSame(x2, x2);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " Cast((JulianDay(@MethodConst0) - JulianDay(@MethodConst1)) *1 As INTEGER)", new List() {
+ new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2)
+ }, "DateIsSameDay error");
+ }
+
+ private void Equals()
+ {
+ Expression> exp = it => SqlFunc.Equals(it.Name, "a");
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " (`Name` = @MethodConst0) ", new List() {
+ new SugarParameter("@MethodConst0","a")
+ }, "Equals1 error");
+
+
+ Expression> exp2 = it => SqlFunc.Equals("a", it.Name);
+ SqliteExpressionContext expContext2 = new SqliteExpressionContext();
+ expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
+ var value2 = expContext2.Result.GetString();
+ var pars2 = expContext2.Parameters;
+ base.Check(value2, pars2, " (@MethodConst0 = `Name`) ", new List() {
+ new SugarParameter("@MethodConst0","a")
+ }, "Equals2 error");
+ }
+ private void Equals_2()
+ {
+ Expression> exp = it => SqlFunc.Equals(it.Name, it.Name);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " (`Name` = `Name`) ", new List() {
+ new SugarParameter("@MethodConst0","a")
+ }, "Equals1 error");
+
+
+ Expression> exp2 = it => SqlFunc.Equals("a", "a2");
+ SqliteExpressionContext expContext2 = new SqliteExpressionContext();
+ expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
+ var value2 = expContext2.Result.GetString();
+ var pars2 = expContext2.Parameters;
+ base.Check(value2, pars2, " (@MethodConst0 = @MethodConst1) ", new List() {
+ new SugarParameter("@MethodConst0","a"),new SugarParameter("@MethodConst1","a2")
+ }, "Equals2 error");
+ }
+
+ private void Contains()
+ {
+ Expression> exp = it => SqlFunc.Contains(it.Name, "a");
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " (`Name` like '%'||@MethodConst0||'%') ", new List() {
+ new SugarParameter("@MethodConst0","a")
+ }, "Contains error");
+ }
+ private void Contains2(string name="a")
+ {
+ Expression> exp = it => SqlFunc.Contains(it.Name, name);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, " (`Name` like '%'||@MethodConst0||'%') ", new List() {
+ new SugarParameter("@MethodConst0","a")
+ }, "Contains2 error");
+ }
+
+ private void ExtendContainsArray() {
+ var array = new string[] { "1", "2" }.ToList();
+ Expression> exp = it => array.Contains(it.Name);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, null, " (`Name` IN ('1','2')) ", null, "Contains2 error");
+ }
+
+ private void ContainsArray()
+ {
+ string[] array = new string[] { "1", "2" };
+ Expression> exp = it => SqlFunc.ContainsArray(array, it.Name);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, null, " (`Name` IN ('1','2')) ", null, "Contains2 error");
+ }
+
+ private void Trim()
+ {
+ Expression> exp = it => SqlFunc.Trim(" a") == it.Name;
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "((rtrim(ltrim(@MethodConst0))) = `Name` )", new List() {
+ new SugarParameter("@MethodConst0"," a")
+ }, "Trim error");
+ }
+
+ private void ToUpper()
+ {
+ Expression> exp = it => "a" == SqlFunc.ToUpper(it.Id);
+ SqliteExpressionContext expContext = new SqliteExpressionContext();
+ expContext.Resolve(exp, ResolveExpressType.WhereSingle);
+ var value = expContext.Result.GetString();
+ var pars = expContext.Parameters;
+ base.Check(value, pars, "( @Const0 = (UPPER(`Id`)) )", new List() {
+ new SugarParameter("@Const0","a")
+ }, "ToUpper error");
+ }
+ private void ToLower()
+ {
+ Expression