mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 16:50:33 +08:00
Update demo
This commit is contained in:
74
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/DataTest.cs
Normal file
74
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/DataTest.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
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 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.Empty,
|
||||
Guid2 = null,
|
||||
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<DataTestInfo>(insertObject).ExecuteReturnIdentity();
|
||||
var data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||
if (
|
||||
insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
|
||||
insertObject.Decimal1 != data.Decimal1 ||
|
||||
insertObject.Float1 != 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");
|
||||
}
|
||||
data.Float1= data.Float1+1;
|
||||
db.Updateable(data).ExecuteCommand();
|
||||
data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||
if (
|
||||
insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
|
||||
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");
|
||||
}
|
||||
|
||||
db.Insertable(new DataTestInfo2() { }).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/DataTest2.cs
Normal file
39
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/DataTest2.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class DataTest2 : UnitTestBase
|
||||
{
|
||||
public interface IEntity<T> {
|
||||
T ID { get; set; }
|
||||
}
|
||||
public abstract class Entity<T> : IEntity<T>
|
||||
{
|
||||
public virtual T ID { get; set; }
|
||||
}
|
||||
public class MyModel: Entity<int>
|
||||
{
|
||||
public override int ID { get; set; }
|
||||
}
|
||||
private DataTest2() { }
|
||||
public DataTest2(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var db = GetInstance();
|
||||
var t1 = db.Queryable<MyModel>().AS("Student").ToList();
|
||||
}
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
75
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Delete.cs
Normal file
75
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Delete.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
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<Student>().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<Student>().With(SqlWith.RowLock).ToSql();
|
||||
base.Check(@"DELETE FROM [STudent] WITH(ROWLOCK) ",
|
||||
null,
|
||||
t2.Key,
|
||||
null, "Delte t2 error"
|
||||
);
|
||||
|
||||
//by primary key
|
||||
var t3 = db.Deleteable<Student>().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<Student>().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<Student>().Where(it=>it.Id==1).ToSql();
|
||||
base.Check(@"DELETE FROM [STudent] WHERE ( [ID] = @Id0 ) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1)
|
||||
}, t5.Key, t5.Value, "Delte t5 error");
|
||||
|
||||
var t6 = db.Deleteable<Student>().Where("id=@id",new { id=1}).ToSql();
|
||||
base.Check(@"DELETE FROM [STudent] WHERE id=@id", new List<SugarParameter>() {
|
||||
new SugarParameter("@id",1)
|
||||
}, t6.Key, t6.Value, "Delte t6 error");
|
||||
|
||||
var t7 = base.GetInstanceByAttribute().Deleteable<DeleteTestTable>().Where(new List<DeleteTestTable>() {
|
||||
new DeleteTestTable() { Id=1, Id2="x" },
|
||||
new DeleteTestTable() { Id=2, Id2="x1" }
|
||||
}).ToSql();
|
||||
base.Check("DELETE FROM [DeleteTestTable] WHERE (([Id]=N'1'AND [Id2]=N'x')OR ([Id]=N'2'AND [Id2]=N'x1')) ",null, t7.Key, null,
|
||||
"Delte t7 error");
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteTestTable {
|
||||
[SugarColumn(IsPrimaryKey =true)]
|
||||
public int Id { get; set; }
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public string Id2 { get; set; }
|
||||
}
|
||||
}
|
||||
39
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/EnumTest.cs
Normal file
39
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/EnumTest.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OrmTest.Demo;
|
||||
using OrmTest.Models;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class EnumTest : UnitTestBase
|
||||
{
|
||||
private EnumTest() { }
|
||||
public EnumTest(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
|
||||
var db = GetInstance();
|
||||
var shoolValue = SchoolEnum.HarvardUniversity;
|
||||
var enums = new SchoolEnum[] { shoolValue, SchoolEnum.UniversityOfOxford };
|
||||
var list = db.Queryable<StudentEnum>().AS("student").Where(it => it.SchoolId == shoolValue).Select(it=>it.SchoolId).ToList();
|
||||
|
||||
var x = new StudentEnum()
|
||||
{
|
||||
Name = shoolValue.ToString(),
|
||||
SchoolId = shoolValue
|
||||
};
|
||||
var x2 = db.Queryable<StudentEnum>().AS("student").Where(it => enums.Contains(it.SchoolId)).ToSql();
|
||||
var id= db.Insertable(x).AS("student").ExecuteReturnIdentity();
|
||||
var data = db.Queryable<StudentEnum>().AS("student").InSingle(id);
|
||||
shoolValue = SchoolEnum.UniversityOfOxford;
|
||||
var sql= db.Updateable<StudentEnum>().AS("student").UpdateColumns(it=>new StudentEnum() { Name="a" , SchoolId= shoolValue }).Where(it=>it.Id==id).ToSql();
|
||||
var sql2 = db.Updateable<StudentEnum>().AS("student").UpdateColumns(it => new StudentEnum() { Name = "a", SchoolId = SchoolEnum.UniversityOfOxford }).Where(it => it.Id == id).ToSql();
|
||||
var sql3 = db.Updateable<StudentEnum>().AS("student").UpdateColumns(it => it.SchoolId == shoolValue ).ToSql();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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();
|
||||
FieldMultiple2();
|
||||
}
|
||||
base.End("Filed Test");
|
||||
}
|
||||
private void FieldSingle()
|
||||
{
|
||||
Expression<Func<Student, object>> 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<Func<Student, object>> 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");
|
||||
}
|
||||
|
||||
private void FieldMultiple2()
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it =>SqlFunc.AggregateAvg(it.Id);
|
||||
ExpressionContext expContext = GetContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.FieldMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
Check(selectorValue, null, "AVG([it].[Id])", null, "FieldMultiple error");
|
||||
}
|
||||
public ExpressionContext GetContext()
|
||||
{
|
||||
return new SqlServerExpressionContext();//可以更换
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,799 @@
|
||||
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
|
||||
MappingColumn();
|
||||
IIF();
|
||||
IIF2();
|
||||
IIF3();
|
||||
IIF4();
|
||||
IIF5();
|
||||
#region StringIsNullOrEmpty
|
||||
HasValue();
|
||||
HasNumber();
|
||||
StringIsNullOrEmpty();
|
||||
StringIsNullOrEmpty2();
|
||||
StringIsNullOrEmpty3();
|
||||
StringIsNullOrEmpty4();
|
||||
StringIsNullOrEmpty5();
|
||||
#endregion
|
||||
ToUpper();
|
||||
ToLower();
|
||||
Trim();
|
||||
Contains();
|
||||
Contains2();
|
||||
Contains3();
|
||||
ContainsArray();
|
||||
StartsWith();
|
||||
EndsWith();
|
||||
Between();
|
||||
Equals();
|
||||
Equals_2();
|
||||
DateIsSameByDay();
|
||||
DateIsSameByType();
|
||||
DateAddDay();
|
||||
DateAddByType();
|
||||
DateValue();
|
||||
ToInt32();
|
||||
ToInt64();
|
||||
ToDate();
|
||||
Tostring();
|
||||
ToDecimal();
|
||||
ToGuid();
|
||||
ToDouble();
|
||||
ToBool();
|
||||
Substring();
|
||||
Replace();
|
||||
Length();
|
||||
Time();
|
||||
|
||||
Test1();
|
||||
}
|
||||
base.End("Method Test");
|
||||
}
|
||||
|
||||
private void Test1()
|
||||
{
|
||||
var ids = new int[] { 1, 2, 3 };
|
||||
Expression<Func<Student, bool>> exp = it => ids.Contains(it.Id)&&!SqlFunc.IsNullOrEmpty(it.Name);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(([Id] IN ('1','2','3')) AND NOT( [Name]='' OR [Name] IS NULL ))", new List<SugarParameter>() {
|
||||
|
||||
}, "Test1 error");
|
||||
}
|
||||
|
||||
private void ExtendToString()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id.ToString() == "a";
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST([Id] AS NVARCHAR(MAX)) = @Const0 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0","a")
|
||||
}, "ExtendToString error");
|
||||
}
|
||||
|
||||
private void ConvetToString()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => Convert.ToString(it.Id) == "a";
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST([Id] AS NVARCHAR(MAX)) = @Const0 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0","a")
|
||||
}, "ConvetToString error");
|
||||
}
|
||||
|
||||
|
||||
private void Length()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.Length("aaaa") > 1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(LEN(@MethodConst0) > @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","aaaa"),new SugarParameter("@Const1",1)
|
||||
}, "Length error");
|
||||
|
||||
Length2();
|
||||
Length3();
|
||||
}
|
||||
|
||||
private void Length2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Name.Length > 1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(LEN([Name])> @Length1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Length1",1)
|
||||
}, "Length2 error");
|
||||
}
|
||||
|
||||
private void Length3()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Name.Length > "a".Length;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(LEN([Name])> @Length1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Length1",1)
|
||||
}, "Length3 error");
|
||||
}
|
||||
|
||||
private void Time()
|
||||
{
|
||||
TimeSpan s = TimeSpan.Parse("11:22:22");
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToTime("11:12:59")==s;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS TIME) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","11:12:59"),new SugarParameter("@Const1",s)
|
||||
}, "Time error");
|
||||
}
|
||||
|
||||
|
||||
private void Replace()
|
||||
{
|
||||
var x2 = Guid.NewGuid();
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.Replace("aaaa", "a", "1") == "a";
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
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<SugarParameter>() {
|
||||
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<Func<Student, bool>> exp = it => SqlFunc.Substring("aaaa", 0, 2) == "a";
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
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<SugarParameter>() {
|
||||
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<Func<Student, bool>> exp = it =>"aaaa".Substring(0, 2)== "a";
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
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<SugarParameter>() {
|
||||
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<Func<Student, bool>> exp = it => SqlFunc.ToBool("true") == true;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS BIT) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","true"),new SugarParameter("@Const1",(bool)true)
|
||||
}, "ToBool error");
|
||||
}
|
||||
|
||||
private void ToDouble()
|
||||
{
|
||||
var x2 = Guid.NewGuid();
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDouble("2") == 2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS FLOAT) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","2"),new SugarParameter("@Const1",(Double)2)
|
||||
}, "ToDouble error");
|
||||
}
|
||||
|
||||
private void ToGuid()
|
||||
{
|
||||
var x2 = Guid.NewGuid();
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToGuid("A94027A3-476E-478D-8228-F4054394B874") == x2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS UNIQUEIDENTIFIER) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","A94027A3-476E-478D-8228-F4054394B874"),new SugarParameter("@Const1",x2)
|
||||
}, "ToGuid error");
|
||||
}
|
||||
|
||||
private void ToDecimal()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDecimal("22") == 1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS MONEY) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","22"),new SugarParameter("@Const1",(decimal)1)
|
||||
}, "ToDecimal error");
|
||||
}
|
||||
|
||||
private void Tostring()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToString("2015-1-1") == "a";
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS NVARCHAR(MAX)) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1","a")
|
||||
}, "Tostring error");
|
||||
}
|
||||
|
||||
private void ToDate()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDate("2015-1-1") == x2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
|
||||
}, "ToDate error");
|
||||
}
|
||||
private void ExtendDate()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => Convert.ToDateTime("2015-1-1") == x2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
|
||||
}, "ExtendDate error");
|
||||
}
|
||||
|
||||
private void ToInt64()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToInt64("3") == 1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS BIGINT) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",(Int64)1)
|
||||
}, "ToInt64 error");
|
||||
}
|
||||
|
||||
private void ToInt32()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.ToInt32("3") == 1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(CAST(@MethodConst0 AS INT) = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",1)
|
||||
}, "ToInt32 error");
|
||||
}
|
||||
|
||||
private void DateValue()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.DateValue(x2, DateType.Year) == 1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " (DateName(Year,@MethodConst0) = @Const2 ) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0",x2),new SugarParameter("@Const2",1)
|
||||
}, "DateValue error");
|
||||
}
|
||||
|
||||
private void StartsWith()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.StartsWith(it.Name, "a");
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ([Name] like @MethodConst0+'%') ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a")
|
||||
}, "StartsWith error");
|
||||
}
|
||||
private void EndsWith()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.EndsWith(it.Name, "a");
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ([Name] like '%'+@MethodConst0) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a")
|
||||
}, "EndsWith");
|
||||
}
|
||||
private void Between()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.Between(it.Name, 1, 2);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
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<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0",1),new SugarParameter("@MethodConst1",2),
|
||||
}, "Between error");
|
||||
}
|
||||
|
||||
private void DateAddByType()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.DateAdd(x2, 11, DateType.Millisecond) == x2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "((DATEADD(Millisecond,@MethodConst1,@MethodConst0)) = @Const3 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2)
|
||||
|
||||
}, "DateAddByType error");
|
||||
}
|
||||
private void DateAddDay()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.DateAdd(x2, 1) == x2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "((DATEADD(day,@MethodConst1,@MethodConst0)) = @Const2 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",1),new SugarParameter("@Const2",x2)
|
||||
}, "DateAddDay error");
|
||||
|
||||
DateAddDay2();
|
||||
DateAddDay3();
|
||||
}
|
||||
|
||||
private void DateAddDay2()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<DataTestInfo, bool>> exp = it =>it.Datetime2.Value.AddHours(10) == x2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "((DATEADD(Hour,@MethodConst1,[Datetime2])) = @Const2 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst1",10)
|
||||
,new SugarParameter("@Const2",x2)
|
||||
}, "DateAddDay2 error");
|
||||
}
|
||||
|
||||
private void DateAddDay3()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => x2.AddHours(1) == x2;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "((DATEADD(Hour,@MethodConst2,@MethodConst1)) = @Const3 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst2",1),
|
||||
new SugarParameter("@MethodConst1",x2)
|
||||
,new SugarParameter("@Const3",x2)
|
||||
}, "DateAddDay3 error");
|
||||
}
|
||||
|
||||
private void DateIsSameByType()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.DateIsSame(x2, x2, DateType.Millisecond);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " (DATEDIFF(Millisecond,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2)
|
||||
}, "DateIsSameByType error");
|
||||
}
|
||||
private void DateIsSameByDay()
|
||||
{
|
||||
var x2 = DateTime.Now;
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.DateIsSame(x2, x2);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(DATEDIFF(day,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2)
|
||||
}, "DateIsSameDay error");
|
||||
}
|
||||
|
||||
private void Equals()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.Equals(it.Name, "a");
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ([Name] = @MethodConst0) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a")
|
||||
}, "Equals1 error");
|
||||
|
||||
|
||||
Expression<Func<Student, bool>> exp2 = it => SqlFunc.Equals("a", it.Name);
|
||||
SqlServerExpressionContext expContext2 = new SqlServerExpressionContext();
|
||||
expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
|
||||
var value2 = expContext2.Result.GetString();
|
||||
var pars2 = expContext2.Parameters;
|
||||
base.Check(value2, pars2, " (@MethodConst0 = [Name]) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a")
|
||||
}, "Equals2 error");
|
||||
}
|
||||
private void Equals_2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.Equals(it.Name, it.Name);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ([Name] = [Name]) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a")
|
||||
}, "Equals1 error");
|
||||
|
||||
|
||||
Expression<Func<Student, bool>> exp2 = it => SqlFunc.Equals("a", "a2");
|
||||
SqlServerExpressionContext expContext2 = new SqlServerExpressionContext();
|
||||
expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
|
||||
var value2 = expContext2.Result.GetString();
|
||||
var pars2 = expContext2.Parameters;
|
||||
base.Check(value2, pars2, " (@MethodConst0 = @MethodConst1) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a"),new SugarParameter("@MethodConst1","a2")
|
||||
}, "Equals2 error");
|
||||
}
|
||||
|
||||
private void Contains()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.Contains(it.Name, "a");
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ([Name] like '%'+@MethodConst0+'%') ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a")
|
||||
}, "Contains error");
|
||||
}
|
||||
private void Contains2(string name="a")
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.Contains(it.Name, name);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ([Name] like '%'+@MethodConst0+'%') ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a")
|
||||
}, "Contains2 error");
|
||||
}
|
||||
private void Contains3(string name = "a")
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => !SqlFunc.Contains(it.Name, name)&&it.Id==1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(NOT ([Name] like '%'+@MethodConst0+'%') AND( [Id] = @Id1 ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","a"),
|
||||
new SugarParameter("@Id1",1)
|
||||
}, "Contains3 error");
|
||||
}
|
||||
|
||||
private void ExtendContainsArray() {
|
||||
var array = new string[] { "1", "2" }.ToList();
|
||||
Expression<Func<Student, bool>> exp = it => array.Contains(it.Name);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
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<Func<Student, bool>> exp = it => SqlFunc.ContainsArray(array, it.Name);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
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<Func<Student, bool>> exp = it => SqlFunc.Trim(" a") == it.Name;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "((rtrim(ltrim(@MethodConst0))) = [Name] )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0"," a")
|
||||
}, "Trim error");
|
||||
}
|
||||
|
||||
private void ToUpper()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => "a" == SqlFunc.ToUpper(it.Id);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( @Const0 = (UPPER([Id])) )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0","a")
|
||||
}, "ToUpper error");
|
||||
}
|
||||
private void ToLower()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => "a" == SqlFunc.ToLower(it.Id);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( @Const0 = (LOWER([Id])) )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0","a")
|
||||
}, "ToLower error");
|
||||
}
|
||||
|
||||
#region StringIsNullOrEmpty
|
||||
private void StringIsNullOrEmpty()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 2 || SqlFunc.IsNullOrEmpty(it.Id); ;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( [Id] > @Id0 ) OR ( [Id]='' OR [Id] IS NULL ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",2)
|
||||
}, "StringIsNullOrEmpty error");
|
||||
}
|
||||
private void StringIsNullOrEmpty2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(true); ;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst1",true),
|
||||
new SugarParameter("@Id0",2)
|
||||
}, "StringIsNullOrEmpty2 error");
|
||||
}
|
||||
private void StringIsNullOrEmpty3()
|
||||
{
|
||||
int a = 1;
|
||||
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(a); ;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst1",1),
|
||||
new SugarParameter("@Id0",2)
|
||||
}, "StringIsNullOrEmpty3 error");
|
||||
}
|
||||
private void StringIsNullOrEmpty4()
|
||||
{
|
||||
WhereConst.name = "xx";
|
||||
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(WhereConst.name); ;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst1","xx"),
|
||||
new SugarParameter("@Id0",2)
|
||||
}, "StringIsNullOrEmpty4 error");
|
||||
}
|
||||
private void StringIsNullOrEmpty5()
|
||||
{
|
||||
WhereConst.name = "xx";
|
||||
Expression<Func<Student, bool>> exp = it => !SqlFunc.IsNullOrEmpty(WhereConst.name); ;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "NOT( @MethodConst0='' OR @MethodConst0 IS NULL )", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","xx")
|
||||
}, "StringIsNullOrEmpty5 error");
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void HasValue()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.HasValue(it.Name);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Name]<>'' AND [Name] IS NOT NULL )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "HasValue error");
|
||||
HasValue2(1);
|
||||
}
|
||||
private void HasValue2(int p = 1)
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.CreateTime.HasValue;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
@"( [it].[CreateTime]<>'' AND [it].[CreateTime] IS NOT NULL )", null, selectorValue, null,
|
||||
"Select.HasValue2 Error");
|
||||
}
|
||||
private void HasNumber()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.HasNumber(it.Id);
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Id]>0 AND [Id] IS NOT NULL )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
|
||||
}, "HasNumber error");
|
||||
}
|
||||
private void MappingColumn() {
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.MappingColumn(it.Id,"Name") == 1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(Name = @Const1 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Const1",1)
|
||||
}, "MappingColumn error");
|
||||
}
|
||||
private void IIF()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2)==1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( CASE WHEN ( [Id] = @Id0 ) THEN @MethodConst1 ELSE @MethodConst2 END ) = @Const3 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@MethodConst1",1),
|
||||
new SugarParameter("@MethodConst2",2),
|
||||
new SugarParameter("@Const3",1)
|
||||
}, "IIF error");
|
||||
}
|
||||
|
||||
private void IIF2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(SqlFunc.Contains(it.Name,"a"), 1, 2)==1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( CASE WHEN ([Name] like '%'+@MethodConst0+'%') THEN @MethodConst1 ELSE @MethodConst2 END ) = @Const3 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@MethodConst0","a"),
|
||||
new SugarParameter("@MethodConst1",1),
|
||||
new SugarParameter("@MethodConst2",2),
|
||||
new SugarParameter("@Const3",1)
|
||||
}, "IIF2 error");
|
||||
}
|
||||
|
||||
private void IIF3()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(SqlFunc.Contains(it.Name, "a"), true, false) == true;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( CASE WHEN ([Name] like '%'+@MethodConst0+'%') THEN @MethodConst1 ELSE @MethodConst2 END ) = @Const3 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@MethodConst0","a"),
|
||||
new SugarParameter("@MethodConst1",true),
|
||||
new SugarParameter("@MethodConst2",false),
|
||||
new SugarParameter("@Const3",true)
|
||||
}, "IIF3 error");
|
||||
}
|
||||
|
||||
private void IIF4()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => SqlFunc.IIF(true, it.Bool1, it.Bool2) == true;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( CASE WHEN ( 1 = 1 ) THEN [Bool1] ELSE [Bool2] END ) = @Const0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Const0",true)
|
||||
}, "IIF4 error");
|
||||
}
|
||||
|
||||
private void IIF5()
|
||||
{
|
||||
Expression<Func<DataTestInfo, bool>> exp = it => SqlFunc.IIF(true,Convert.ToBoolean(it.Datetime1), SqlFunc.ToBool(it.Datetime1)) == false;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( CASE WHEN ( 1 = 1 ) THEN CAST([Datetime1] AS BIT) ELSE CAST([Datetime1] AS BIT) END ) = @Const0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Const0",false)
|
||||
}, "IIF5 error");
|
||||
IIF6();
|
||||
}
|
||||
|
||||
private void IIF6()
|
||||
{
|
||||
var dt = DateTime.Now.Date;
|
||||
Expression <Func<DataTestInfo, bool>> exp = it => SqlFunc.IIF(dt == it.Datetime1,it.Datetime1, it.Datetime1) == dt;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.MappingColumns = new MappingColumnList();
|
||||
expContext.MappingColumns.Add("Datetime1", "Datetime2", "DataTestInfo");
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( CASE WHEN ( @Datetime10 = [Datetime2] ) THEN [Datetime2] ELSE [Datetime2] END ) = @Const1 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Datetime10",dt),
|
||||
new SugarParameter("@Const1",dt)
|
||||
}, "IIF6 error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
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 Select : UnitTestBase
|
||||
{
|
||||
private Select() { }
|
||||
public Select(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
single();
|
||||
single2();
|
||||
single3();
|
||||
single4();
|
||||
single5();
|
||||
single6();
|
||||
single7();
|
||||
single8();
|
||||
Multiple();
|
||||
Multiple2();
|
||||
singleDynamic();
|
||||
MultipleDynamic();
|
||||
}
|
||||
base.End("Select Test");
|
||||
}
|
||||
|
||||
private void single7()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, DataTestInfo2>> exp =it => new DataTestInfo2() { Bool1=it.Bool1 , Bool2=it.Bool2 };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@"[Bool1] AS [Bool1] , [Bool2] AS [Bool2] ",
|
||||
new List<SugarParameter>()
|
||||
{
|
||||
|
||||
},
|
||||
"Select.single7 Error");
|
||||
}
|
||||
|
||||
private void single8()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, object>> exp = it => new { Bool1 = it.Bool1, Bool2 = it.Bool2 };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@"[Bool1] AS [Bool1] , [Bool2] AS [Bool2] ",
|
||||
new List<SugarParameter>()
|
||||
{
|
||||
|
||||
},
|
||||
"Select.single8 Error");
|
||||
}
|
||||
|
||||
private void Multiple()
|
||||
{
|
||||
Expression<Func<Student, School, object>> exp = (it, school) => new Student() { Name = "a", Id = it.Id, SchoolId = school.Id, TestId = it.Id + 1 };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" @constant0 AS [Name] , [it].[Id] AS [Id] , [school].[Id] AS [SchoolId] , ( [it].[Id] + @Id1 ) AS [TestId] ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant0","a"),
|
||||
new SugarParameter("@Id1",1)
|
||||
},
|
||||
"Select.Multiple Error");
|
||||
}
|
||||
private void Multiple2()
|
||||
{
|
||||
Expression<Func<Student, School, object>> exp = (it, school) => new ViewModelStudent3() { SchoolName=school.Name,Id=SqlFunc.GetSelfAndAutoFill(it.Id) };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" [school].[Name] AS [SchoolName] ,it.*",
|
||||
new List<SugarParameter>(){
|
||||
|
||||
},
|
||||
"Select.Multiple Error");
|
||||
}
|
||||
|
||||
|
||||
private void MultipleDynamic()
|
||||
{
|
||||
Expression<Func<Student, School, object>> exp = (it, school) => new { Name = "a", Id = it.Id / 2, SchoolId = school.Id };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" @constant0 AS [Name] , ( [it].[Id] / @Id1 ) AS [Id] , [school].[Id] AS [SchoolId] ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant0","a"),
|
||||
new SugarParameter("@Id1", 2)},
|
||||
"Select.MultipleDynamic Error");
|
||||
}
|
||||
private void single()
|
||||
{
|
||||
int p = 1;
|
||||
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id = it.Id, SchoolId = p,TestId=it.Id+11 };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" @constant0 AS [Name] , [Id] AS [Id] , @constant1 AS [SchoolId] , ( [Id] + @Id2 ) AS [TestId] ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant0","a"),
|
||||
new SugarParameter("@constant1",1),
|
||||
new SugarParameter("@Id2",11 ) },
|
||||
"Select.single Error");
|
||||
}
|
||||
private void single2(int p=1)
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id = it.Id, SchoolId = p, TestId = it.Id + 11 };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" @constant0 AS [Name] , [Id] AS [Id] , @constant1 AS [SchoolId] , ( [Id] + @Id2 ) AS [TestId] ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant0","a"),
|
||||
new SugarParameter("@constant1",1),
|
||||
new SugarParameter("@Id2",11 ) },
|
||||
"Select.single Error");
|
||||
}
|
||||
private void single3(int p = 1)
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => new DataTestInfo() { Datetime1=DateTime.Now, String=it.Name};
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
@" @constant0 AS [Datetime1] , [Name] AS [String] ", null,selectorValue,null,
|
||||
"Select.single3 Error");
|
||||
}
|
||||
|
||||
private void single4(int p = 1)
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => it.CreateTime.HasValue;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
@"( [it].[CreateTime]<>'' AND [it].[CreateTime] IS NOT NULL )", null, selectorValue, null,
|
||||
"Select.single4 Error");
|
||||
}
|
||||
|
||||
private void single5()
|
||||
{
|
||||
var p =(DateTime?) DateTime.Now;
|
||||
Expression<Func<Student, object>> exp = it => p.HasValue;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
@"( @constant0<>'' AND @constant0 IS NOT NULL )", new List<SugarParameter>() {
|
||||
new SugarParameter("@constant0",p)
|
||||
}, selectorValue, pars,
|
||||
"Select.single5 Error");
|
||||
}
|
||||
private void single6()
|
||||
{
|
||||
var p = (DateTime?)DateTime.Now;
|
||||
Expression<Func<Student, object>> exp = it => p.Value;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.IsSingle = false;
|
||||
expContext.Resolve(exp, ResolveExpressType.FieldSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
@" @Const0 ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",p)
|
||||
}, selectorValue, pars,
|
||||
"Select.single6 Error");
|
||||
}
|
||||
|
||||
private void singleDynamic()
|
||||
{
|
||||
string a = "a";
|
||||
Expression<Func<Student, object>> exp = it => new { x = it.Id, shoolid = 1, name = a,p=it.Id*2 };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" [Id] AS [x] , @constant0 AS [shoolid] , @constant1 AS [name] , ( [Id] * @Id2 ) AS [p] ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant0",1),
|
||||
new SugarParameter("@constant1","a"),
|
||||
new SugarParameter("@Id2",2)},
|
||||
"Select.singleDynamic Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,517 @@
|
||||
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 Where : UnitTestBase
|
||||
{
|
||||
private Where() { }
|
||||
public Where(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
whereSingle31();
|
||||
whereSingle30();
|
||||
whereSingle29("22");
|
||||
whereSingle28();
|
||||
whereSingle27();
|
||||
whereSingle26();
|
||||
whereSingle25();
|
||||
whereSingle24();
|
||||
whereSingle23();
|
||||
whereSingle22();
|
||||
whereSingle21();
|
||||
whereSingle20();
|
||||
whereSingle19();
|
||||
whereSingle18();
|
||||
whereSingle17();
|
||||
whereSingle16();
|
||||
whereSingle15();
|
||||
whereSingle1();
|
||||
whereSingle2();
|
||||
whereSingle3();
|
||||
whereSingle4();
|
||||
whereSingle5();
|
||||
whereSingle6();
|
||||
whereSingle7(new Student() { Id = 1 });
|
||||
whereSingle8(new Student() { Id = 1 });
|
||||
whereSingle9(new Student() { Id = 1 });
|
||||
whereSingle10();
|
||||
whereSingle11();
|
||||
whereSingle12();
|
||||
whereSingle13();
|
||||
whereSingle14();
|
||||
whereSingle15();
|
||||
WhereMultiple1();
|
||||
WhereMultiple2();
|
||||
|
||||
}
|
||||
base.End("Where Test");
|
||||
}
|
||||
|
||||
private void whereSingle30()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Name == wc.name2;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Name] = @Name0 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Name0","a")
|
||||
}, "whereSingle30");
|
||||
}
|
||||
|
||||
private void whereSingle31()
|
||||
{
|
||||
bool? b = false;
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool2== b.Value;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Bool2] = @Bool20 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Bool20",false)
|
||||
}, "whereSingle31");
|
||||
|
||||
whereSingle32();
|
||||
}
|
||||
|
||||
|
||||
private void whereSingle32()
|
||||
{
|
||||
bool? b = false;
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool1 == b;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Bool1] = @Bool10 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Bool10",false)
|
||||
}, "whereSingle32");
|
||||
}
|
||||
|
||||
public string Get28(string a) {
|
||||
return a + "1";
|
||||
}
|
||||
|
||||
private void whereSingle29(string p2)
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => Get28("22") == p2;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " (@constant0 = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@constant0","221"),
|
||||
new SugarParameter("@Const1","22")
|
||||
}, "whereSingle28");
|
||||
}
|
||||
private void whereSingle28()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => Get28("22")=="22";
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " (@constant0 = @Const1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@constant0","221"),
|
||||
new SugarParameter("@Const1","22")
|
||||
}, "whereSingle28");
|
||||
}
|
||||
private void whereSingle27() {
|
||||
var schoolData = new School() { Id = 100, Name = "x" };
|
||||
Expression<Func<Student, bool>> exp = it => it.Name.Contains(schoolData.Name);
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ([it].[Name] like '%'+@MethodConst0+'%') ", new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0","x")
|
||||
}, "whereSingle27");
|
||||
}
|
||||
private void WhereMultiple1()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 1;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [it].[Id] > @Id0 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1)
|
||||
}, "WhereMultiple1");
|
||||
}
|
||||
private void WhereMultiple2()
|
||||
{
|
||||
string name = "a";
|
||||
WhereConst.name = "a1";
|
||||
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != name || it.Id == 1) || it.Name == WhereConst.name;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " (((( [it].[Id] > @Id0 ) AND ( [it].[Name] <> @Name1 )) OR ( [it].[Id] = @Id2 )) OR ( [it].[Name] = @Name3 ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@Name1","a"),
|
||||
new SugarParameter("@Id2",1),
|
||||
new SugarParameter("@Name3","a1")
|
||||
}, "WhereMultiple2");
|
||||
}
|
||||
private void whereSingle1()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 1;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Id] > @Id0 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1)
|
||||
}, "whereSingle1");
|
||||
}
|
||||
private void whereSingle2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => 1 > it.Id;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( @Id0 > [Id] )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1)
|
||||
}, "whereSingle2");
|
||||
}
|
||||
private void whereSingle3()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 1 || it.Name == "a";
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " (( [Id] > @Id0 ) OR ( [Name] = @Name1 ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@Name1","a")
|
||||
}, "whereSingle3");
|
||||
}
|
||||
private void whereSingle4()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != "a") || it.Name == "a1";
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ((( [Id] > @Id0 ) AND ( [Name] <> @Name1 )) OR ( [Name] = @Name2 )) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@Name1","a"),
|
||||
new SugarParameter("@Name2","a1")
|
||||
}, "whereSingle4");
|
||||
}
|
||||
private void whereSingle5()
|
||||
{
|
||||
string name = "a";
|
||||
WhereConst.name = "a1";
|
||||
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != name) || it.Name == WhereConst.name;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ((( [Id] > @Id0 ) AND ( [Name] <> @Name1 )) OR ( [Name] = @Name2 )) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@Name1","a"),
|
||||
new SugarParameter("@Name2","a1")
|
||||
}, "whereSingle5");
|
||||
}
|
||||
private void whereSingle6()
|
||||
{
|
||||
string name = "a";
|
||||
WhereConst.name = "a1";
|
||||
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != name||it.Id==1) || it.Name == WhereConst.name;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " (((( [Id] > @Id0 ) AND ( [Name] <> @Name1 )) OR ( [Id] = @Id2 )) OR ( [Name] = @Name3 ))", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@Name1","a"),
|
||||
new SugarParameter("@Id2",1),
|
||||
new SugarParameter("@Name3","a1")
|
||||
}, "whereSingle6");
|
||||
}
|
||||
private void whereSingle7(Student st)
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > st.Id;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Id] > @Id0 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1)
|
||||
}, "whereSingle7");
|
||||
}
|
||||
|
||||
private void whereSingle8(Student st)
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Name == null;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Name] IS NULL )", new List<SugarParameter>() {
|
||||
|
||||
}, "whereSingle8");
|
||||
}
|
||||
|
||||
private void whereSingle9(Student st)
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Name == st.Name;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Name] = @Name0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Name0",null)
|
||||
}, "whereSingle9");
|
||||
}
|
||||
|
||||
|
||||
private void whereSingle10()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => true;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( 1 = 1 )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle10");
|
||||
}
|
||||
|
||||
|
||||
private void whereSingle11()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => !true;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( 1 = 2 )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle11");
|
||||
}
|
||||
|
||||
private void whereSingle12()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool1==true;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Bool1] = @Bool10 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Bool10",true)
|
||||
}, "whereSingle12");
|
||||
}
|
||||
|
||||
private void whereSingle13()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Name!=null;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Name] IS NOT NULL )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle13");
|
||||
}
|
||||
|
||||
private void whereSingle14()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it =>true&& it.Name != null;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( 1 = 1 ) AND( [Name] IS NOT NULL ))", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle14");
|
||||
}
|
||||
|
||||
private void whereSingle15()
|
||||
{
|
||||
Expression<Func<DataTestInfo, bool>> exp = it =>it.Money2 == 1;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Money2] = @Const0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Const0",1)
|
||||
}, "whereSingle15");
|
||||
}
|
||||
|
||||
private void whereSingle16()
|
||||
{
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("key", "x1");
|
||||
Expression<Func<DataTestInfo, bool>> exp = it => it.String == dic["key"];
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [String] = @Const0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Const0",dic["key"])
|
||||
}, "whereSingle16");
|
||||
}
|
||||
|
||||
private void whereSingle17()
|
||||
{
|
||||
Expression<Func<DataTestInfo, bool>> exp = it =>true&&it.String.Contains("a");
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "(( 1 = 1 ) AND ([String] like '%'+@MethodConst1+'%') )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@MethodConst1","a")
|
||||
}, "whereSingle17");
|
||||
}
|
||||
|
||||
private void whereSingle18()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => !it.Bool1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "NOT ( [Bool1]=1 ) ", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle18");
|
||||
}
|
||||
private void whereSingle19()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool2.Value==false;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Bool2] = @Value0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Value0",false)
|
||||
}, "whereSingle19");
|
||||
}
|
||||
private void whereSingle20()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool2.Value == it.Bool1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Bool2] = [Bool1] )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle19");
|
||||
}
|
||||
|
||||
private void whereSingle21()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool2.Value;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Bool2]=1 )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle21");
|
||||
}
|
||||
|
||||
private void whereSingle22()
|
||||
{
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => !it.Bool2.Value;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "NOT ( [Bool2]=1 ) ", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
}, "whereSingle22");
|
||||
}
|
||||
|
||||
private void whereSingle23()
|
||||
{
|
||||
decimal? val = 1;
|
||||
Expression<Func<DataTestInfo, bool>> exp = it => it.Decimal2==val.Value;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Decimal2] = @Const0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Const0",val)
|
||||
}, "whereSingle23");
|
||||
}
|
||||
private void whereSingle24()
|
||||
{
|
||||
Expression<Func<DataTestInfo, bool>> exp = it => it.Datetime1 > DateTime.Now.Date;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( [Datetime1] > @Datetime10 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Datetime10",DateTime.Now.Date)
|
||||
}, "whereSingle24");
|
||||
}
|
||||
private void whereSingle26()
|
||||
{
|
||||
var p = DateTime.Now;
|
||||
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool1&&it.Bool1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( ( [Bool1]=1 ) AND ( [Bool1]=1 ) )", new List<SugarParameter>()
|
||||
{
|
||||
|
||||
|
||||
}, "whereSingle26");
|
||||
}
|
||||
private void whereSingle25()
|
||||
{
|
||||
var p = DateTime.Now;
|
||||
Expression<Func<DataTestInfo, bool>> exp = it => it.Datetime1.Date > p.Date;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( CAST( DateName(Year,[Datetime1]) +'-'+ DateName(Month,[Datetime1]) +'-'+ DateName(Day,[Datetime1]) AS DATETIME) > @Date0 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Date0",DateTime.Now.Date),
|
||||
|
||||
}, "whereSingle25");
|
||||
}
|
||||
public static WhereConst wc = new WhereConst() { name2 = "a" };
|
||||
}
|
||||
|
||||
public class WhereConst
|
||||
{
|
||||
public static string name { get; set; }
|
||||
public string name2 { get; set; }
|
||||
}
|
||||
}
|
||||
152
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Insert.cs
Normal file
152
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Insert.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class Insert : UnitTestBase
|
||||
{
|
||||
private Insert() { }
|
||||
public Insert(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var db = GetInstance();
|
||||
var insertObj = new Student() { Name = "jack", CreateTime = Convert.ToDateTime("2010-1-1"), SchoolId=0 };
|
||||
db.IgnoreColumns.Add("TestId", "Student");
|
||||
//db.MappingColumns.Add("id","dbid", "Student");
|
||||
|
||||
var t1 = db.Insertable(insertObj).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent]
|
||||
([SchoolId],[Name],[CreateTime])
|
||||
VALUES
|
||||
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||
new SugarParameter("@Name","jack")
|
||||
}, t1.Key, t1.Value, "Insert t1 error"
|
||||
);
|
||||
|
||||
|
||||
//Insert reutrn Command Count
|
||||
var t2 = db.Insertable(insertObj).ExecuteReturnEntity();
|
||||
|
||||
db.IgnoreColumns = null;
|
||||
//Only insert Name
|
||||
var t3 = db.Insertable(insertObj).InsertColumns(it => new { it.Name }).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent]
|
||||
([Name])
|
||||
VALUES
|
||||
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
||||
new SugarParameter("@Name","jack")
|
||||
}, t3.Key, t3.Value, "Insert t3 error");
|
||||
|
||||
|
||||
//Ignore Name and TestId
|
||||
var t4 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent]
|
||||
([SchoolId],[CreateTime])
|
||||
VALUES
|
||||
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||
}, t4.Key, t4.Value, "Insert t4 error"
|
||||
);
|
||||
|
||||
//Ignore Name and TestId
|
||||
var t5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK)
|
||||
([SchoolId],[CreateTime])
|
||||
VALUES
|
||||
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||
}, t5.Key, t5.Value, "Insert t5 error"
|
||||
);
|
||||
//Use Lock
|
||||
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK)
|
||||
([SchoolId],[Name],[CreateTime])
|
||||
VALUES
|
||||
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||
new SugarParameter("@Name","jack")
|
||||
}, t6.Key, t6.Value, "Insert t6 error"
|
||||
);
|
||||
|
||||
var insertObj2 = new Student() { Name = null,SchoolId=0, CreateTime = Convert.ToDateTime("2010-1-1") };
|
||||
var t8 = db.Insertable(insertObj2).Where(true/* Is insert null */, true/*off identity*/).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent]
|
||||
([ID],[SchoolId],[CreateTime])
|
||||
VALUES
|
||||
(@ID,@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId", 0),
|
||||
new SugarParameter("@ID", 0),
|
||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1"))
|
||||
},
|
||||
t8.Key,
|
||||
t8.Value,
|
||||
"Insert t8 error"
|
||||
);
|
||||
|
||||
|
||||
db.IgnoreColumns = new IgnoreColumnList();
|
||||
db.IgnoreColumns.Add("TestId", "Student");
|
||||
|
||||
//Insert List<T>
|
||||
var insertObjs = new List<Student>();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
insertObjs.Add(new Student() { Name = "name" + i });
|
||||
}
|
||||
var s9 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).With(SqlWith.UpdLock).ToSql();
|
||||
|
||||
insertObj.Name = null;
|
||||
var t10 = db.Insertable(insertObj).ExecuteCommand();
|
||||
|
||||
var t11 = db.Insertable(new MyStudent() { Id = 1, Name = "张三" }).AS("Student").ToSql();
|
||||
base.Check(@"INSERT INTO [Student]
|
||||
([Name])
|
||||
VALUES
|
||||
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
||||
new SugarParameter("@Name","张三")
|
||||
}, t11.Key, t11.Value, "Insert t11 error");
|
||||
|
||||
|
||||
var t12 = db.Insertable<Student>(new { Name = "a" }).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent]
|
||||
([Name])
|
||||
VALUES
|
||||
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
||||
new SugarParameter("@Name","a")
|
||||
}, t12.Key, t12.Value, "Insert t12 error");
|
||||
|
||||
var t13 = db.Insertable<Student>(new Dictionary<string, object>() { {"id",0 },{ "name","2"} }).ToSql();
|
||||
base.Check(@"INSERT INTO [STudent]
|
||||
([Name])
|
||||
VALUES
|
||||
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
||||
new SugarParameter("@Name","2")
|
||||
}, t13.Key, t13.Value, "Insert t13 error");
|
||||
}
|
||||
}
|
||||
|
||||
public class MyStudent {
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
68
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Mapping .cs
Normal file
68
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Mapping .cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class Mapping : UnitTestBase
|
||||
{
|
||||
private Mapping() { }
|
||||
public Mapping(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
||||
var db = GetInstance();
|
||||
var t1 = db.Queryable<Student>().Where(it => it.Id == 1).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE ( [ID] = @Id0 ) ", null, t1.Key, null, "Mapping t1 error");
|
||||
|
||||
db.MappingColumns.Add("Id", "id", "School");
|
||||
var t2 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id
|
||||
})
|
||||
.Where(st => st.Id == 1)
|
||||
.Where((st, sc) => sc.Id == 1)
|
||||
.Where((st, sc) => sc.Id == st.Id)
|
||||
.GroupBy(st => st.Id)
|
||||
.GroupBy((st, sc) => sc.Id).OrderBy(st => st.Id, OrderByType.Asc)
|
||||
.Select((st, sc) => new { stid = st.Id, scid = sc.Id }).ToSql();
|
||||
base.Check(@"SELECT [st].[ID] AS [stid] , [sc].[id] AS [scid] FROM [STudent] st Left JOIN [School] sc ON ( [st].[SchoolId] = [sc].[id] ) WHERE ( [st].[ID] = @Id0 ) AND ( [sc].[id] = @Id1 ) AND ( [sc].[id] = [st].[ID] )GROUP BY [st].[ID],[sc].[id] ORDER BY [st].[ID] ASC ",
|
||||
null, t2.Key, null, " Mapping t2 error");
|
||||
var x2 = GetInstance();
|
||||
|
||||
var q = x2.Queryable<Student>().AS("t");
|
||||
var t3 = q.ToSql();
|
||||
var t4 = q.ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [t] ", null, t3.Key, null, "Mapping t3 error");
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [t] ", null, t4.Key, null, "Mapping t3 error");
|
||||
|
||||
var x3 = GetInstance2();
|
||||
x3.MappingTables.Add("Student", "studenT");
|
||||
int count = 0;
|
||||
var t5 = x3.Queryable<Student>().ToPageList(1,2,ref count);
|
||||
}
|
||||
|
||||
public new SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
return db;
|
||||
}
|
||||
public SqlSugarClient GetInstance2()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
db.CurrentConnectionConfig.AopEvents.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars));
|
||||
Console.WriteLine();
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
147
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Query/JoinQuery.cs
Normal file
147
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Query/JoinQuery.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using OrmTest.Models;
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class JoinQuery : UnitTestBase
|
||||
{
|
||||
private JoinQuery() { }
|
||||
public JoinQuery(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
Q1();
|
||||
Q2();
|
||||
Q3();
|
||||
Q4();
|
||||
q5();
|
||||
q6();
|
||||
q7();
|
||||
}
|
||||
base.End("Method Test");
|
||||
}
|
||||
|
||||
private void q6()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
var join6 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id
|
||||
}).Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = SqlFunc.AggregateMin(sc.Id) }).ToSql();
|
||||
|
||||
string sql = @"SELECT [st].[Name] AS [Name] , MIN([sc].[Id]) AS [SchoolId] FROM [STudent] st Left JOIN [School] sc ON ( [st].[SchoolId] = [sc].[Id] ) ";
|
||||
base.Check(sql, null, join6.Key, null, "join 6 Error");
|
||||
}
|
||||
}
|
||||
|
||||
private void q7()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
var join7 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id
|
||||
}).Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = SqlFunc.AggregateMin(sc.Id * 1) }).ToSql();
|
||||
|
||||
string sql = @"SELECT [st].[Name] AS [Name] , MIN(( [sc].[Id] * @Id0 )) AS [SchoolId] FROM [STudent] st Left JOIN [School] sc ON ( [st].[SchoolId] = [sc].[Id] ) ";
|
||||
base.Check(sql, new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1)
|
||||
}, join7.Key, join7.Value, "join 7 Error");
|
||||
}
|
||||
}
|
||||
|
||||
private void q5()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
db.MappingTables.Add("School", "SchoolTable");
|
||||
var join5 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select(st => st)
|
||||
.GroupBy(st => new { st.Id, st.Name })
|
||||
.ToSql();
|
||||
string sql = @"SELECT st.* FROM [STudent] st ,[SchoolTable] sc WHERE ( [st].[SchoolId] = [sc].[Id] )GROUP BY [st].[ID],[st].[Name] ";
|
||||
base.Check(sql, null, join5.Key, null, "join 5 Error");
|
||||
}
|
||||
}
|
||||
|
||||
private void Q4()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
db.MappingTables.Add("School", "SchoolTable");
|
||||
var join4 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select(st => st).ToSql();
|
||||
string sql = @"SELECT st.* FROM [STudent] st ,[SchoolTable] sc WHERE ( [st].[SchoolId] = [sc].[Id] ) ";
|
||||
base.Check(sql, null, join4.Key, null, "join 4 Error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Q3()
|
||||
{
|
||||
using (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.*").ToSql();
|
||||
string sql = @"SELECT st.* FROM [Student] st Left JOIN [School] sh ON sh.id=st.schoolid WHERE st.id>@id ";
|
||||
base.Check(sql, new List<SugarParameter>() { new SugarParameter("@id", 1) }, join3.Key, join3.Value, "join 3 Error");
|
||||
}
|
||||
}
|
||||
|
||||
public void Q1()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
var join1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id
|
||||
}).Where(st => st.Id > 0).Select<Student>("*").ToSql();
|
||||
base.Check(@"SELECT * FROM [STudent] st Left JOIN [School] sc ON ( [st].[SchoolId] = [sc].[Id] ) WHERE ( [st].[ID] > @Id0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",0)
|
||||
}, join1.Key, join1.Value, "join 1 Error");
|
||||
}
|
||||
}
|
||||
public void Q2()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
var join2 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id
|
||||
}).Where(st => st.Id > 2).Select<Student>("*").ToSql();
|
||||
base.Check(@"SELECT * FROM [STudent] st Left JOIN [School] sc ON ( [st].[SchoolId] = [sc].[Id] ) WHERE ( [st].[ID] > @Id0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",2)
|
||||
}, join2.Key, join2.Value, "join 2 Error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public new SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.SqlServer,
|
||||
AopEvents = new AopEvents()
|
||||
{
|
||||
OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
172
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Query/SelectQuery.cs
Normal file
172
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Query/SelectQuery.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using OrmTest.Models;
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class SelectQuery : UnitTestBase
|
||||
{
|
||||
private SelectQuery() { }
|
||||
public SelectQuery(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
Q2();
|
||||
}
|
||||
base.End("Method Test");
|
||||
}
|
||||
|
||||
public void Q2()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
//db.Database.IsEnableLogEvent = true;
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
};
|
||||
|
||||
|
||||
#region dr ot entity
|
||||
db.IgnoreColumns.Add("TestId", "Student");
|
||||
var s1 = db.Queryable<Student>().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
|
||||
var s2 = db.Queryable<Student>().Select(it => new { id = it.Id, w = new { x = it } }).ToList();
|
||||
var s3 = db.Queryable<Student>().Select(it => new { newid = it.Id }).ToList();
|
||||
var s4 = db.Queryable<Student>().Select(it => new { newid = it.Id, obj = it }).ToList();
|
||||
var s5 = db.Queryable<Student>().Select(it => new ViewModelStudent2 { Student = it, Name = it.Name }).ToList();
|
||||
#endregion
|
||||
|
||||
|
||||
#region sql and parameters validate
|
||||
var t1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Inner,st.Id==sc.Id
|
||||
}).GroupBy(st => st.Id).Having(st => SqlFunc.AggregateAvg(st.Id) == 1).Select(st => new { avgId = SqlFunc.AggregateAvg(st.Id) }).ToSql();
|
||||
base.Check("SELECT AVG([st].[ID]) AS [avgId] FROM [STudent] st Inner JOIN [School] sc ON ( [st].[ID] = [sc].[Id] ) GROUP BY [st].[ID] HAVING (AVG([st].[ID]) = @Const0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",1)
|
||||
}
|
||||
,
|
||||
t1.Key, t1.Value, " select t1 Error");
|
||||
|
||||
|
||||
var t2 = db.Queryable<School, School>((st, st2) => new object[] {
|
||||
JoinType.Left,st.Id==st2.Id
|
||||
})
|
||||
.Where(st => st.Id > 0)
|
||||
.Select((st, st2) => new { stid = st.Id, scId = st2.Id, xx = st }).ToSql();
|
||||
|
||||
base.Check("SELECT [st].[Id] AS [stid] , [st2].[Id] AS [scId] , [st].[Id] AS [School.Id] , [st].[Name] AS [School.Name] FROM [School] st Left JOIN [School] st2 ON ( [st].[Id] = [st2].[Id] ) WHERE ( [st].[Id] > @Id0 ) "
|
||||
, new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",0)
|
||||
}, t2.Key, t2.Value, "select t2 Error");
|
||||
|
||||
|
||||
var t3 = db.Queryable<Student, School, School>((st, sc, sc2) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id,
|
||||
JoinType.Left,sc2.Id==sc.Id
|
||||
}).Where(st => st.Id > 0)
|
||||
.Select<School>((st) => new School() { Id = st.Id }).ToSql();
|
||||
base.Check("SELECT [st].[ID] AS [Id] FROM [STudent] st Left JOIN [School] sc ON ( [st].[SchoolId] = [sc].[Id] ) Left JOIN [School] sc2 ON ( [sc2].[Id] = [sc].[Id] ) WHERE ( [st].[ID] > @Id0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",0)
|
||||
}, t3.Key, t3.Value, "select t3 Error");
|
||||
|
||||
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
base.Check(" SELECT COUNT(1) FROM (SELECT [st].[ID] FROM [STudent] st Left JOIN [School] sc ON ( [st].[SchoolId] = [sc].[Id] ) Left JOIN [School] sc2 ON ( [sc2].[Id] = [sc].[Id] ) GROUP BY [st].[ID] ) CountTable ",
|
||||
null, sql, null, "select t4 Error");
|
||||
};
|
||||
|
||||
var t4 = db.Queryable<Student, School, School>((st, sc, sc2) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id,
|
||||
JoinType.Left,sc2.Id==sc.Id
|
||||
}).GroupBy(st => st.Id).Select(st => st.Id).Count();
|
||||
|
||||
DateTime? result = DateTime.Now;
|
||||
var t5 = db.Queryable<Student>().Where(it => it.CreateTime > result.Value.Date).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE ( [CreateTime] > @Const0 )",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",result.Value.Date)
|
||||
}, t5.Key, t5.Value, "select t5 Error");
|
||||
db.Ado.IsEnableLogEvent = false;
|
||||
|
||||
var t6 = db.Queryable<DataTestInfo2>().Where(it => SqlFunc.HasValue(it.Bool2) == false).ToSql();
|
||||
base.Check("SELECT [PK],[Bool1],[Bool2],[Text1] FROM [DataTestInfo2] WHERE (( CASE WHEN ( [Bool2]<>'' AND [Bool2] IS NOT NULL ) THEN 1 ELSE 0 END ) = @Const0 )",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",false)
|
||||
}, t6.Key, t6.Value, "select t6 Error");
|
||||
|
||||
|
||||
var t7 = db.Queryable<Student>().Select(it=>new DataTestInfo2() {
|
||||
Bool1=SqlFunc.IIF(SqlFunc.Subqueryable<Student>().Where(x=>x.Id
|
||||
==it.Id).Any(),true,false)
|
||||
}).ToSql();
|
||||
|
||||
base.Check("SELECT ( CASE WHEN (EXISTS ( SELECT * FROM [STudent] WHERE ( [ID] = [it].[ID] ) )) THEN @MethodConst0 ELSE @MethodConst1 END ) AS [Bool1] FROM [STudent] it ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@MethodConst0",true),
|
||||
new SugarParameter("@MethodConst1",false)
|
||||
}, t7.Key, t7.Value, "select t7 Error");
|
||||
#endregion
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t8 = db.Queryable<Student, School, School>((st, sc, sc2) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id,
|
||||
JoinType.Left,sc2.Id==sc.Id
|
||||
}).Where(st => st.Id > 0)
|
||||
.Select<School>((st1) => new School() { Id = st1.Id }).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!ex.Message.Contains("English Message : Join st needs to be the same as Select st1")){
|
||||
throw new Exception("selec t8 error");
|
||||
}
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t8 = db.Queryable<Student, School>((st, sc) =>st.Id==sc.Id).Where(st => st.Id > 0)
|
||||
.Where(x=>x.Id==1)
|
||||
.Select<School>((st) => new School() { Id = st.Id }).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
if (!ex.Message.Contains("English Message : Join st needs to be the same as Where x")){
|
||||
throw new Exception("selec t8 error");
|
||||
}
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t8 = db.Queryable<Student, School>((st, sc) => st.Id == sc.Id)
|
||||
.Sum(x =>x.Id );
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
if (!ex.Message.Contains("English Message : Join st needs to be the same as Sum x")){
|
||||
throw new Exception("selec t8 error");
|
||||
}
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
151
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Query/SingleQuery.cs
Normal file
151
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Query/SingleQuery.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using OrmTest.Models;
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class SingleQuery : UnitTestBase
|
||||
{
|
||||
private SingleQuery() { }
|
||||
public SingleQuery(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
Q2();
|
||||
}
|
||||
base.End("Method Test");
|
||||
}
|
||||
|
||||
public void Q2()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
var t1 = db.Queryable<Student>().ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]", null, t1.Key, null, "single t1 Error");
|
||||
|
||||
var t2 = db.Queryable<Student>().With(SqlWith.NoLock).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WITH(NOLOCK)", null, t2.Key, null, "single t2 Error");
|
||||
|
||||
var t3 = db.Queryable<Student>().OrderBy(it=>it.Id).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] ORDER BY [ID] ASC", null, t3.Key, null, "single t3 Error");
|
||||
|
||||
var t4 = db.Queryable<Student>().OrderBy(it => it.Id).Take(3).ToSql();
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM [STudent] ) T WHERE RowIndex BETWEEN 1 AND 3", null, t4.Key, null, "single t4 Error");
|
||||
|
||||
var t5 = db.Queryable<Student>().OrderBy(it => it.Id).Skip(3).ToSql();
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM [STudent] ) T WHERE RowIndex BETWEEN 4 AND 9223372036854775807", null, t5.Key,null, "single t5 Error");
|
||||
|
||||
int pageIndex = 2;
|
||||
int pageSize = 10;
|
||||
var t6 = db.Queryable<Student>().OrderBy(it => it.Id,OrderByType.Desc).Skip((pageIndex-1)*pageSize).Take(pageSize).ToSql();
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM [STudent] ) T WHERE RowIndex BETWEEN 11 AND 20", null, t6.Key, null, "single t6 Error");
|
||||
|
||||
|
||||
int studentCount=db.Ado.GetInt("select count(1) from Student");
|
||||
var countIsSuccess=db.Queryable<Student>().Count()== studentCount;
|
||||
if (!countIsSuccess) {
|
||||
throw new Exception(" single countIsSuccess Error");
|
||||
}
|
||||
|
||||
var t7 = db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToPageList(pageIndex,pageSize,ref studentCount);
|
||||
countIsSuccess = studentCount == db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize * pageIndex).Count();
|
||||
if (!countIsSuccess)
|
||||
{
|
||||
throw new Exception("single t7 Error");
|
||||
}
|
||||
|
||||
int studentMin = db.Ado.GetInt("select min(id) from Student");
|
||||
var minIsSuccess = db.Queryable<Student>().Min(it=>it.Id) == studentMin;
|
||||
if (!minIsSuccess)
|
||||
{
|
||||
throw new Exception("single minIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentMax = db.Ado.GetInt("select max(id) from Student");
|
||||
var maxIsSuccess = db.Queryable<Student>().Max(it => it.Id) == studentMax;
|
||||
if (!maxIsSuccess)
|
||||
{
|
||||
throw new Exception("single maxIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentAvg = db.Ado.GetInt("select avg(id) from Student");
|
||||
var avgIsSuccess = db.Queryable<Student>().Avg(it => it.Id) == studentAvg;
|
||||
if (!maxIsSuccess)
|
||||
{
|
||||
throw new Exception(" single avgIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentSum = db.Ado.GetInt("select sum(id) from Student");
|
||||
var sumIsSuccess = db.Queryable<Student>().Sum(it => it.Id) == studentSum;
|
||||
if (!sumIsSuccess)
|
||||
{
|
||||
throw new Exception("single sumIsSuccess Error");
|
||||
}
|
||||
|
||||
var t8 = db.Queryable<Student>()
|
||||
.Where(it=>it.Id==1)
|
||||
.WhereIF(true,it=> SqlFunc.Contains(it.Name,"a"))
|
||||
.OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize ).With(SqlWith.NoLock).ToSql();
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM [STudent] WITH(NOLOCK) WHERE ( [ID] = @Id0 ) AND ([Name] like '%'+@MethodConst1+'%') ) T WHERE RowIndex BETWEEN 11 AND 20", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),new SugarParameter("@MethodConst1","a")
|
||||
}, t8.Key, t8.Value,"single t8 Error");
|
||||
|
||||
|
||||
|
||||
var t9 = db.Queryable<Student>()
|
||||
.In(1)
|
||||
.Select(it => new { it.Id, it.Name,x=it.Id }).ToSql();
|
||||
base.Check("SELECT [ID] AS [Id] , [Name] AS [Name] , [ID] AS [x] FROM [STudent] WHERE [Id] IN (@InPara0) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@InPara0",1) },t9.Key,t9.Value, "single t9 error");
|
||||
|
||||
var t10 = db.Queryable<Student>().Select(it => new StudentEnum() { Id = SqlFunc.GetSelfAndAutoFill(it.Id) }).ToSql();
|
||||
base.Check("SELECT * FROM [STudent] ", null, t10.Key, t10.Value, "single t10 error");
|
||||
|
||||
var t11= db.Queryable<Student>().GroupBy("id").OrderBy("id").Select("id").ToSql();
|
||||
base.Check("SELECT id FROM [STudent] GROUP BY id ORDER BY id ", null, t11.Key, t11.Value, "single t11 error");
|
||||
|
||||
|
||||
var t12 = db.Queryable<Student>().Where(it=>it.Id!=null).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE ( [ID] IS NOT NULL )", null, t12.Key, t12.Value, "single t12 error");
|
||||
|
||||
var id = 1;
|
||||
var t13 = db.Queryable<Student>().Where(it => SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id&&s.Id==id).Max(s => s.Id) == 1).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] it WHERE ((SELECT MAX([Id]) FROM [School] WHERE (( [Id] = [it].[ID] ) AND ( [Id] = @Id0 ))) = @Const1 )",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@Const1",1)
|
||||
}, t13.Key, t13.Value, "single t13 error ");
|
||||
|
||||
|
||||
var t14 = db.Queryable<Student>()
|
||||
.Where(it => it.Name == "a" && SqlFunc.HasValue(it.Name)).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE (( [Name] = @Name0 ) AND ( [Name]<>'' AND [Name] IS NOT NULL ))",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Name0","a")
|
||||
}, t14.Key, t14.Value, "single t14 error ");
|
||||
|
||||
|
||||
var t15 = db.Queryable<CapitalEntity>()
|
||||
.Select(x => new
|
||||
{
|
||||
|
||||
TGYArea = SqlFunc.AggregateSum(SqlFunc.IIF(x.FlatProp == "1", x.Areas, 0))
|
||||
}).ToSql();
|
||||
base.Check("SELECT SUM(( CASE WHEN ( [FlatProp] = @FlatProp0 ) THEN [Areas] ELSE @MethodConst1 END )) AS [TGYArea] FROM [RENT_CAPITAL] ", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@FlatProp0","1"),
|
||||
new SugarParameter("@MethodConst1",0)
|
||||
}, t15.Key, t15.Value, "single t15 error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class Attribute : UnitTestBase
|
||||
{
|
||||
public Attribute(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class AutoClose : UnitTestBase
|
||||
{
|
||||
public AutoClose(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
//IsAutoCloseConnection
|
||||
for (int i = 0; i < this.Count; i++)
|
||||
{
|
||||
var db = GetInstance();
|
||||
var x = db.Queryable<Student>().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class MapColumn : UnitTestBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class MapTable : UnitTestBase
|
||||
{
|
||||
public void Init()
|
||||
{
|
||||
//IsAutoCloseConnection
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
var db = GetInstance();
|
||||
var x = db.Queryable<Student>().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/SqlRemark.cs
Normal file
45
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/SqlRemark.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class SqlRemark : UnitTestBase
|
||||
{
|
||||
private SqlRemark() { }
|
||||
public SqlRemark(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var db = GetInstance();
|
||||
|
||||
//column remak
|
||||
if (db.DbMaintenance.IsAnyColumnRemark("id", "student"))
|
||||
{
|
||||
db.DbMaintenance.DeleteColumnRemark("id", "student");
|
||||
base.Check(false.ToString(), null, db.DbMaintenance.IsAnyColumnRemark("id", "student").ToString(), null, "SqlRemark error");
|
||||
}
|
||||
else {
|
||||
db.DbMaintenance.AddColumnRemark("id", "student","hhXX");
|
||||
base.Check(true.ToString(), null, db.DbMaintenance.IsAnyColumnRemark("id", "student").ToString(), null, "SqlRemark error");
|
||||
}
|
||||
|
||||
|
||||
//table remak
|
||||
if (db.DbMaintenance.IsAnyTableRemark("student"))
|
||||
{
|
||||
db.DbMaintenance.DeleteTableRemark("student");
|
||||
base.Check(false.ToString(), null, db.DbMaintenance.IsAnyTableRemark("student").ToString(), null, "SqlRemark error");
|
||||
}
|
||||
else
|
||||
{
|
||||
db.DbMaintenance.AddTableRemark("student", "hhXX");
|
||||
base.Check(true.ToString(), null, db.DbMaintenance.IsAnyTableRemark("student").ToString(), null, "SqlRemark error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/UnitTestBase.cs
Normal file
61
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/UnitTestBase.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
using System.Linq;
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class UnitTestBase
|
||||
{
|
||||
public int Count { get; set; }
|
||||
private DateTime BeginTime { get; set; }
|
||||
private DateTime EndTime { get; set; }
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
this.BeginTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public void End(string title)
|
||||
{
|
||||
this.EndTime = DateTime.Now;
|
||||
Console.WriteLine(title + " \r\nCount: " + this.Count + "\r\nTime: " + (this.EndTime - this.BeginTime).TotalSeconds + " Seconds \r\n");
|
||||
}
|
||||
|
||||
internal void Check(string value, List<SugarParameter> pars, string validValue, List<SugarParameter> validPars, string errorMessage)
|
||||
{
|
||||
if (value.Trim() != validValue.Trim())
|
||||
{
|
||||
throw new Exception(errorMessage);
|
||||
}
|
||||
if (pars != null && pars.Count > 0)
|
||||
{
|
||||
if (pars.Count != validPars.Count)
|
||||
{
|
||||
throw new Exception(errorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in pars)
|
||||
{
|
||||
if (!validPars.Any(it => it.ParameterName.Equals(item.ParameterName) && it.Value.ObjToString().Equals(item.Value.ObjToString())))
|
||||
{
|
||||
throw new Exception(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
return db;
|
||||
}
|
||||
|
||||
public SqlSugarClient GetInstanceByAttribute()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType=InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
188
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Update.cs
Normal file
188
Src/Asp.Net/SqlServerTest/_OldTest/UnitTest/Update.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class Update : UnitTestBase
|
||||
{
|
||||
private Update() { }
|
||||
public Update(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
|
||||
public 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<Student>() { updateObj,new Student() { Id=2,Name="sun",SchoolId=0 } }.ToArray();
|
||||
db.IgnoreColumns.Add("TestId", "Student");
|
||||
//db.MappingColumns.Add("id","dbid", "Student");
|
||||
|
||||
var t1 = db.Updateable(updateObj).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@Name", "jack")
|
||||
}, t1.Key, t1.Value,"Update t1 error");
|
||||
|
||||
//update reutrn Command Count
|
||||
var t2 = db.Updateable(updateObj).ExecuteCommand();
|
||||
|
||||
db.IgnoreColumns = null;
|
||||
//Only update Name
|
||||
var t3 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name }).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[Name]=@Name WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@Name", "jack")
|
||||
}, t3.Key, t3.Value, "Update t3 error");
|
||||
|
||||
//Ignore Name and TestId
|
||||
var t4 = db.Updateable(updateObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@SchoolId", 0),
|
||||
new SugarParameter("@ID",1),
|
||||
}, t4.Key, t4.Value, "Update t4 error");
|
||||
|
||||
//Ignore Name and TestId
|
||||
var t5 = db.Updateable(updateObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||
base.Check(@"UPDATE [STudent] WITH(UPDLOCK) SET
|
||||
[SchoolId]=@SchoolId,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@SchoolId", 0),
|
||||
new SugarParameter("@ID",1),
|
||||
}, t5.Key, t5.Value, "Update t5 error");
|
||||
|
||||
|
||||
//Use Lock
|
||||
var t6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ToSql();
|
||||
base.Check(@"UPDATE [STudent] WITH(UPDLOCK) SET
|
||||
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@Name", "jack")
|
||||
}, t6.Key, t6.Value, "Update t6 error");
|
||||
|
||||
|
||||
// //update List<T>
|
||||
// var t7 = db.Updateable(updateObjs).With(SqlWith.UpdLock).ToSql();
|
||||
// base.Check(@"UPDATE S SET S.[SchoolId]=T.[SchoolId],S.[Name]=T.[Name],S.[CreateTime]=T.[CreateTime] FROM [STudent] S WITH(UPDLOCK) INNER JOIN (
|
||||
|
||||
// SELECT N'1' AS ID,N'0' AS SchoolId,N'jack' AS Name,'2017-05-21 09:56:12.610' AS CreateTime
|
||||
//UNION ALL
|
||||
// SELECT N'2' AS ID,N'0' AS SchoolId,N'sun' AS Name,NULL AS CreateTime
|
||||
|
||||
|
||||
// ) T ON S.[Id]=T.[Id]
|
||||
// ; ", null, t7.Key, null,"Update t7 error");
|
||||
|
||||
//Re Set Value
|
||||
var t8 = db.Updateable(updateObj)
|
||||
.ReSetValue(it=>it.Name==(it.Name+1)).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId, [Name] =( [Name] + @Const0 ),[CreateTime]=@CreateTime WHERE [Id]=@Id",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@Const0", 1)
|
||||
}, t8.Key, t8.Value, "Update t8 error"
|
||||
);
|
||||
|
||||
//Where By Expression
|
||||
var t9 = db.Updateable(updateObj)
|
||||
.Where(it => it.Id==1).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE ( [ID] = @Id0 )",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@Id0",1),
|
||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@Name", "jack") },t9.Key,t9.Value,"Upate t9 error"
|
||||
);
|
||||
updateObj.SchoolId = 18;
|
||||
string name = "x";
|
||||
var t10 = db.Updateable<Student>().UpdateColumns(it => new Student() { Name =name, SchoolId=updateObj.SchoolId }).Where(it=>it.Id==11).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId] = @Const1 , [Name] = @Const0 WHERE ( [ID] = @Id2 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Const1",18),
|
||||
new SugarParameter("@Const0","x"),
|
||||
new SugarParameter("@Id2",11)},
|
||||
t10.Key,
|
||||
t10.Value,
|
||||
"Update 10 error"
|
||||
);
|
||||
var t11 = db.Updateable<DataTestInfo>().UpdateColumns(it => new DataTestInfo() { Datetime1=DateTime.MaxValue }).Where(it => it.Int1 == 11).ToSql();
|
||||
base.Check(@"UPDATE [DataTestInfo] SET
|
||||
[Datetime1] = @constant0 WHERE ( [Int1] = @Int11 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Int11",11),
|
||||
new SugarParameter("@constant0",DateTime.MaxValue) },
|
||||
t11.Key,
|
||||
t11.Value,
|
||||
"Update 11 error"
|
||||
);
|
||||
|
||||
var t12 = db.Updateable<DataTestInfo>().UpdateColumns(it => new DataTestInfo() { Int2 = it.Int2+1 }).Where(it => it.Int1 == 11).ToSql();
|
||||
base.Check(@"UPDATE [DataTestInfo] SET
|
||||
[Int2] = ( [Int2] + @Const0 ) WHERE ( [Int1] = @Int11 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Int11",11),
|
||||
new SugarParameter("@Const0",1) },
|
||||
t12.Key,
|
||||
t12.Value,
|
||||
"Update 12 error"
|
||||
);
|
||||
|
||||
|
||||
|
||||
var t13 = db.Updateable<Student>(new { Name = "a", id=1 }).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[Name]=@Name WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
new SugarParameter("@Name","a"),
|
||||
new SugarParameter("@ID",1)
|
||||
}, t13.Key, t13.Value, "Update t13 error");
|
||||
|
||||
var t14 = db.Updateable<Student>(new Dictionary<string, object>() { { "id", 0 }, { "name", "2" } }).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[Name]=@Name WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
new SugarParameter("@Name", "2"),
|
||||
new SugarParameter("@ID", 0)
|
||||
}, t14.Key, t14.Value, "Update t14 error");
|
||||
|
||||
|
||||
var t15 = db.Updateable(new StudentTest() { Id = 1, Name = "1" }).AS("student").ToSql();
|
||||
base.Check(@"UPDATE [student] SET
|
||||
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE [Id]=@Id", null, t15.Key, null, "Update t15 error");
|
||||
|
||||
|
||||
var t16= db.Updateable<Student>().UpdateColumns(it => new Student()
|
||||
{
|
||||
SchoolId = SqlFunc.Subqueryable<School>().Where(s => s.Id == it.SchoolId).Select(s => s.Id),
|
||||
Name = "newname"
|
||||
}).Where(it => it.Id == 1).ToSql();
|
||||
|
||||
var t17 = db.Updateable<Student>().UpdateColumns(it => new Student()
|
||||
{
|
||||
SchoolId = SqlFunc.Subqueryable<School>().Where(s => s.Id == it.SchoolId).Select(s => s.Id),
|
||||
Name = "newname"
|
||||
}).Where(it => it.Id == 1).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId] = (SELECT TOP 1 [Id] FROM [School] WHERE ( [Id] =[STudent].[SchoolId] )) , [Name] = @Const0 WHERE ( [ID] = @Id1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0","newname"),
|
||||
new SugarParameter("@Id1","1")
|
||||
}, t17.Key, t17.Value, "Update t17 error");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user