mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
接口整理
This commit is contained in:
@@ -17,11 +17,11 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
//Unit Test
|
//Unit Test
|
||||||
int eachCount = 10;
|
int eachCount = 10;
|
||||||
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 SelectQuery(eachCount).Init();
|
new SelectQuery(eachCount).Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,30 +30,36 @@ namespace OrmTest.UnitTest
|
|||||||
using (var db = GetInstance())
|
using (var db = GetInstance())
|
||||||
{
|
{
|
||||||
db.Database.IsEnableLogEvent = true;
|
db.Database.IsEnableLogEvent = true;
|
||||||
db.Database.LogEventStarting = (sql,pars) =>
|
db.Database.LogEventStarting = (sql, pars) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql+" " + pars);
|
Console.WriteLine(sql + " " + pars);
|
||||||
};
|
};
|
||||||
var list = db.Queryable<School,School>((st,st2)=>new object[] {
|
|
||||||
|
var listx = db.Queryable<School, School>((st, st2) => new object[] {
|
||||||
JoinType.Left,st.Id==st2.Id
|
JoinType.Left,st.Id==st2.Id
|
||||||
})
|
})
|
||||||
.Where<Student,School>((st,sc) => st.Id > 0)
|
.Where(st => st.Id > 0)
|
||||||
.Select(st => new ViewModelStudent { School=st}).ToList();
|
.Select<Student, School, dynamic>((st, sc) => new { st, st.Id, stid = st.Id, scId = sc.Id }).ToList();
|
||||||
|
return;
|
||||||
|
var list = db.Queryable<School, School>((st, st2) => new object[] {
|
||||||
|
JoinType.Left,st.Id==st2.Id
|
||||||
|
}).Where<Student, School>((st, sc) => st.Id > 0)
|
||||||
|
.Select(st => new ViewModelStudent { School = st }).ToList();
|
||||||
|
|
||||||
var list2 = db.Queryable<Student>()
|
var list2 = db.Queryable<Student>()
|
||||||
.Where(st => st.Id > 0)
|
.Where(st => st.Id > 0)
|
||||||
.Select("id").ToList();
|
.Select("id").ToList();
|
||||||
|
|
||||||
var list3 = db.Queryable<Student, School,School>((st, sc,sc2) => new object[] {
|
var list3 = db.Queryable<Student, School, School>((st, sc, sc2) => new object[] {
|
||||||
JoinType.Left,st.SchoolId==sc.Id,
|
JoinType.Left,st.SchoolId==sc.Id,
|
||||||
JoinType.Left,sc2.Id==sc.Id
|
JoinType.Left,sc2.Id==sc.Id
|
||||||
}).Where(st => st.Id > 0)
|
}).Where(st => st.Id > 0)
|
||||||
.Select<School>((st) =>new School() { Id=st.Id}).ToList();
|
.Select<School>((st) => new School() { Id = st.Id }).ToList();
|
||||||
|
|
||||||
var list4 = db.Queryable("Student", "st")
|
var list4 = db.Queryable("Student", "st")
|
||||||
.AddJoinInfo("School", "sh", "sh.id=st.schoolid")
|
.AddJoinInfo("School", "sh", "sh.id=st.schoolid")
|
||||||
.Where("st.id>@id")
|
.Where("st.id>@id")
|
||||||
.AddParameters(new {id=1})
|
.AddParameters(new { id = 1 })
|
||||||
.Select("st.*").ToList();
|
.Select("st.*").ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -214,33 +214,38 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public ISugarQueryable<TResult> Select<T2, TResult>(Expression<Func<T2, TResult>> expression) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<T2, TResult>(Expression<Func<T2, TResult>> expression) where TResult : class, new()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return SelectMehtod<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISugarQueryable<TResult> Select<T2, T3, TResult>(Expression<Func<T2, T3, TResult>> expression) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<T2, T3, TResult>(Expression<Func<T2, T3, TResult>> expression) where TResult : class, new()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return SelectMehtod<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISugarQueryable<TResult> Select<T2, T3, T4, TResult>(Expression<Func<T2, T3, T4, TResult>> expression) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<T2, T3, T4, TResult>(Expression<Func<T2, T3, T4, TResult>> expression) where TResult : class, new()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return SelectMehtod<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISugarQueryable<TResult> Select<T2, T3, T4, T5, TResult>(Expression<Func<T2, T3, T4, T5, TResult>> expression) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<T2, T3, T4, T5, TResult>(Expression<Func<T2, T3, T4, T5, TResult>> expression) where TResult : class, new()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return SelectMehtod<TResult>(expression);
|
||||||
}
|
}
|
||||||
public ISugarQueryable<TResult> Select<T2, T3, T4, T5, T6, TResult>(Expression<Func<T2, T3, T4, T5, T6, TResult>> expression) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<T2, T3, T4, T5, T6, TResult>(Expression<Func<T2, T3, T4, T5, T6, TResult>> expression) where TResult : class, new()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return SelectMehtod<TResult>(expression);
|
||||||
}
|
}
|
||||||
public ISugarQueryable<TResult> Select<T2, T3, T4, T5, T6, T7, TResult>(Expression<Func<T2, T3, T4, T5, T6, T7, TResult>> expression) where TResult : class, new()
|
public ISugarQueryable<TResult> Select<T2, T3, T4, T5, T6, T7, TResult>(Expression<Func<T2, T3, T4, T5, T6, T7, TResult>> expression) where TResult : class, new()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return SelectMehtod<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
|
{
|
||||||
|
return SelectMehtod<TResult>(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISugarQueryable<TResult> SelectMehtod<TResult>(Expression 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.Context = this.Context;
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ namespace SqlSugar
|
|||||||
base.Expression = item;
|
base.Expression = item;
|
||||||
base.Start();
|
base.Start();
|
||||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||||
parameter.Context.Result.Append(base.Context.GetAsString(memberName,parameterName));
|
parameter.Context.Result.Append(base.Context.GetAsString(memberName, parameterName));
|
||||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||||
}
|
}
|
||||||
else if (item is MemberExpression)
|
else if (item is MemberExpression)
|
||||||
@@ -60,7 +61,7 @@ namespace SqlSugar
|
|||||||
base.Expression = item;
|
base.Expression = item;
|
||||||
base.Start();
|
base.Start();
|
||||||
parameter.IsAppendResult();
|
parameter.IsAppendResult();
|
||||||
base.Context.Result.Append(base.Context.GetAsString(memberName,parameter.CommonTempData.ObjToString()));
|
base.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||||
base.Context.Result.CurrentParameter = null;
|
base.Context.Result.CurrentParameter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,9 +82,37 @@ namespace SqlSugar
|
|||||||
base.Context.Result.CurrentParameter = null;
|
base.Context.Result.CurrentParameter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (item.Type.IsClass())
|
||||||
|
{
|
||||||
|
base.Expression = item;
|
||||||
|
base.Start();
|
||||||
|
var shortName = parameter.CommonTempData;
|
||||||
|
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
||||||
|
foreach (var property in listProperties)
|
||||||
|
{
|
||||||
|
if (property.PropertyType.IsClass())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var asName = memberName + "_" + property.Name;
|
||||||
|
var columnName = property.Name;
|
||||||
|
if (Context.IsJoin)
|
||||||
|
{
|
||||||
|
base.Context.Result.Append(Context.GetAsString(asName, columnName, shortName.ObjToString()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base.Context.Result.Append(Context.GetAsString(asName, columnName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user