mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
-
This commit is contained in:
@@ -46,10 +46,11 @@
|
|||||||
<Compile Include="Config.cs" />
|
<Compile Include="Config.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\ExpTestBase.cs" />
|
<Compile Include="UnitTest\ExpressionTest\ExpTestBase.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
|
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
|
||||||
<Compile Include="UnitTest\Query\Join.cs" />
|
<Compile Include="UnitTest\Query\JoinQuery.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
|
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\Select.cs" />
|
<Compile Include="UnitTest\ExpressionTest\Select.cs" />
|
||||||
<Compile Include="UnitTest\Query\Single.cs" />
|
<Compile Include="UnitTest\Query\SelectQuery.cs" />
|
||||||
|
<Compile Include="UnitTest\Query\SingleQuery.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\Where.cs" />
|
<Compile Include="UnitTest\ExpressionTest\Where.cs" />
|
||||||
<Compile Include="Models\School.cs" />
|
<Compile Include="Models\School.cs" />
|
||||||
<Compile Include="Models\Student.cs" />
|
<Compile Include="Models\Student.cs" />
|
||||||
|
@@ -11,18 +11,18 @@ using System.Data.SqlClient;
|
|||||||
using OrmTest.UnitTest;
|
using OrmTest.UnitTest;
|
||||||
namespace OrmTest
|
namespace OrmTest
|
||||||
{
|
{
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//Expression To Sql Unit Test
|
//Unit Test
|
||||||
int eachCount = 1;
|
int eachCount = 1;
|
||||||
new Field(eachCount).Init();
|
new Field(eachCount).Init();
|
||||||
new Where(eachCount).Init();
|
new Where(eachCount).Init();
|
||||||
new Method(eachCount).Init();
|
new Method(eachCount).Init();
|
||||||
new JoinQuery(eachCount).Init();
|
new JoinQuery(eachCount).Init();
|
||||||
new SingleQuery(eachCount).Init();
|
new SingleQuery(eachCount).Init();
|
||||||
|
new SingleQuery(eachCount).Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
60
OrmTest/UnitTest/Query/JoinQuery.cs
Normal file
60
OrmTest/UnitTest/Query/JoinQuery.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
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++)
|
||||||
|
{
|
||||||
|
Q1();
|
||||||
|
Q2();
|
||||||
|
}
|
||||||
|
base.End("Method Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Q1()
|
||||||
|
{
|
||||||
|
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).Select<Student>("*").ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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).Select<Student>("*").ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||||
|
db.Database.IsEnableLogEvent = true;
|
||||||
|
db.Database.LogEventStarting = (sql, pars) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql+" "+pars);
|
||||||
|
};
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -8,10 +8,10 @@ using System.Linq.Expressions;
|
|||||||
using OrmTest.Models;
|
using OrmTest.Models;
|
||||||
namespace OrmTest.UnitTest
|
namespace OrmTest.UnitTest
|
||||||
{
|
{
|
||||||
public class JoinQuery : ExpTestBase
|
public class SelectQuery : ExpTestBase
|
||||||
{
|
{
|
||||||
private JoinQuery() { }
|
private SelectQuery() { }
|
||||||
public JoinQuery(int eachCount)
|
public SelectQuery(int eachCount)
|
||||||
{
|
{
|
||||||
this.Count = eachCount;
|
this.Count = eachCount;
|
||||||
}
|
}
|
||||||
@@ -29,13 +29,10 @@ namespace OrmTest.UnitTest
|
|||||||
{
|
{
|
||||||
using (var db = GetInstance())
|
using (var db = GetInstance())
|
||||||
{
|
{
|
||||||
var list = db.Queryable<Student, School>((st, sc) => new object[] {
|
var list = db.Queryable<Student>().Where(st => st.Id > 0).ToList();
|
||||||
JoinType.Left,st.SchoolId==sc.Id
|
|
||||||
}).Where(st=>st.Id>0).ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SqlSugarClient GetInstance()
|
public SqlSugarClient GetInstance()
|
||||||
{
|
{
|
||||||
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
@@ -207,12 +207,17 @@ namespace SqlSugar
|
|||||||
public ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression) where TResult : class, new()
|
||||||
{
|
{
|
||||||
var reval = InstanceFactory.GetQueryable<TResult>(this.Context.CurrentConnectionConfig);
|
var reval = InstanceFactory.GetQueryable<TResult>(this.Context.CurrentConnectionConfig);
|
||||||
|
reval.Context = this.Context;
|
||||||
|
reval.Pars = this.Pars;
|
||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISugarQueryable<TResult> Select<TResult>(string selectValue) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<TResult>(string selectValue) where TResult : class, new()
|
||||||
{
|
{
|
||||||
var reval = InstanceFactory.GetQueryable<TResult>(this.Context.CurrentConnectionConfig);
|
var reval = InstanceFactory.GetQueryable<TResult>(this.Context.CurrentConnectionConfig);
|
||||||
|
reval.Context = this.Context;
|
||||||
|
reval.Context.SqlBuilder.LambadaQueryBuilder.SelectValue = selectValue;
|
||||||
|
reval.Pars = this.Pars;
|
||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user