mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
-
This commit is contained in:
49
OrmTest/UnitTest/ExpressionTest/ExpTestBase.cs
Normal file
49
OrmTest/UnitTest/ExpressionTest/ExpTestBase.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
using System.Linq;
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class ExpTestBase
|
||||
{
|
||||
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.Equals(item.Value)))
|
||||
{
|
||||
throw new Exception(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
OrmTest/UnitTest/ExpressionTest/Field.cs
Normal file
46
OrmTest/UnitTest/ExpressionTest/Field.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
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:ExpTestBase
|
||||
{
|
||||
private Field() { }
|
||||
public Field(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
FieldSingle();
|
||||
FieldMultiple();
|
||||
}
|
||||
base.End("Filed Test");
|
||||
}
|
||||
private void FieldSingle()
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => it.Name;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.FieldSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
Check(selectorValue, null, "Name", null, "FieldSingle");
|
||||
}
|
||||
private void FieldMultiple()
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => it.Name;
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.FieldMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
Check(selectorValue, null, "it.Name", null, "FieldMultiple");
|
||||
}
|
||||
}
|
||||
}
|
138
OrmTest/UnitTest/ExpressionTest/Method.cs
Normal file
138
OrmTest/UnitTest/ExpressionTest/Method.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
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 : ExpTestBase
|
||||
{
|
||||
private Method() { }
|
||||
public Method(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
#region StringIsNullOrEmpty
|
||||
StringIsNullOrEmpty();
|
||||
StringIsNullOrEmpty2();
|
||||
StringIsNullOrEmpty3();
|
||||
StringIsNullOrEmpty4();
|
||||
ToUpper();
|
||||
ToLower();
|
||||
Trim();
|
||||
Contains();
|
||||
#endregion
|
||||
}
|
||||
base.End("Method Test");
|
||||
}
|
||||
|
||||
private void Contains()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => NBORM.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");
|
||||
}
|
||||
|
||||
private void Trim()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it =>NBORM.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");
|
||||
}
|
||||
|
||||
private void ToUpper()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it =>"a"== NBORM.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");
|
||||
}
|
||||
private void ToLower()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => "a" == NBORM.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");
|
||||
}
|
||||
|
||||
#region StringIsNullOrEmpty
|
||||
private void StringIsNullOrEmpty()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 2 || NBORM.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");
|
||||
}
|
||||
private void StringIsNullOrEmpty2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.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");
|
||||
}
|
||||
private void StringIsNullOrEmpty3()
|
||||
{
|
||||
int a = 1;
|
||||
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.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");
|
||||
}
|
||||
private void StringIsNullOrEmpty4()
|
||||
{
|
||||
WhereConst.name = "xx";
|
||||
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.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");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
99
OrmTest/UnitTest/ExpressionTest/Select.cs
Normal file
99
OrmTest/UnitTest/ExpressionTest/Select.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
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 : ExpTestBase
|
||||
{
|
||||
private Select() { }
|
||||
public Select(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
single();
|
||||
Multiple();
|
||||
singleDynamic();
|
||||
MultipleDynamic();
|
||||
}
|
||||
base.End("Select Test");
|
||||
}
|
||||
|
||||
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.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" @constant1 AS Name , it.Id AS Id , school.Id AS SchoolId , ( it.Id + 1 ) AS TestId ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant1","a")},
|
||||
"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.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" @constant1 AS Name , ( it.Id / 2 ) AS Id , school.Id AS SchoolId ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant1","a")},
|
||||
"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+1 };
|
||||
ExpressionContext expContext = new ExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(
|
||||
selectorValue,
|
||||
pars,
|
||||
@" @constant1 AS Name , Id AS Id , @constant3 AS SchoolId , ( Id + 1 ) AS TestId ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant1","a"),
|
||||
new SugarParameter("@constant3",1)},
|
||||
"Select.single Error");
|
||||
}
|
||||
|
||||
private void singleDynamic()
|
||||
{
|
||||
string a = "a";
|
||||
Expression<Func<Student, object>> exp = it => new { x = it.Id, shoolid = 1, name = a,p=it.Id*1 };
|
||||
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 , @constant2 AS shoolid , @constant3 AS name , ( Id * 1 ) AS p ",
|
||||
new List<SugarParameter>(){
|
||||
new SugarParameter("@constant2",1),
|
||||
new SugarParameter("@constant3","a")},
|
||||
"Select.single Error");
|
||||
}
|
||||
}
|
||||
}
|
146
OrmTest/UnitTest/ExpressionTest/Where.cs
Normal file
146
OrmTest/UnitTest/ExpressionTest/Where.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
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 : ExpTestBase
|
||||
{
|
||||
private Where() { }
|
||||
public Where(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
whereSingle1();
|
||||
whereSingle2();
|
||||
whereSingle3();
|
||||
whereSingle4();
|
||||
whereSingle5();
|
||||
whereSingle6();
|
||||
WhereMultiple1();
|
||||
WhereMultiple2();
|
||||
}
|
||||
base.End("Where Test");
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
public class WhereConst
|
||||
{
|
||||
public static string name { get; set; }
|
||||
}
|
||||
}
|
45
OrmTest/UnitTest/Query/Join.cs
Normal file
45
OrmTest/UnitTest/Query/Join.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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 : ExpTestBase
|
||||
{
|
||||
private JoinQuery() { }
|
||||
public JoinQuery(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 list = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Left,st.SchoolId==sc.Id
|
||||
}).Where(st=>st.Id>0).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
43
OrmTest/UnitTest/Query/Single.cs
Normal file
43
OrmTest/UnitTest/Query/Single.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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 : ExpTestBase
|
||||
{
|
||||
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 list = db.Queryable<Student>().Where(st => st.Id > 0).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user