Browse Source

The Join section can write the conditions

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
a2a4bbd349
  1. 7
      SqlServerTest/Demos/1_Query.cs
  2. 9
      SqlSugar/SqlSugarAccessory.cs

7
SqlServerTest/Demos/1_Query.cs

@ -229,6 +229,13 @@ namespace OrmTest.Demo
.OrderBy((st, sc) => sc.Id, OrderByType.Desc)
.Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = sc.Id }).ToList();
//join 2
var list4_1 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id&& st.Name == "jack"
}).ToList();
//The simple use of Join 2 table
var list5 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select((st,sc)=>new {st.Name,st.Id,schoolName=sc.Name}).ToList();

9
SqlSugar/SqlSugarAccessory.cs

@ -181,8 +181,12 @@ namespace SqlSugar
{
this.CreateQueryable<T>(queryable);
string shortName = string.Empty;
queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(joinExpression, ref shortName, types);
List<SugarParameter> paramters =new List<SugarParameter>();
queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(joinExpression,ref paramters, ref shortName, types);
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
if (paramters != null) {
queryable.SqlBuilder.QueryBuilder.Parameters.AddRange(paramters);
}
}
protected void CreateEasyQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable) where T : class, new()
{
@ -194,7 +198,7 @@ namespace SqlSugar
#endregion
#region Private methods
protected List<JoinQueryInfo> GetJoinInfos(Expression joinExpression, ref string shortName, params Type[] entityTypeArray)
protected List<JoinQueryInfo> GetJoinInfos(Expression joinExpression,ref List<SugarParameter> parameters, ref string shortName, params Type[] entityTypeArray)
{
List<JoinQueryInfo> result = new List<JoinQueryInfo>();
var lambdaParameters = ((LambdaExpression)joinExpression).Parameters.ToList();
@ -204,6 +208,7 @@ namespace SqlSugar
expressionContext.Resolve(joinExpression, ResolveExpressType.Join);
int i = 0;
var joinArray = expressionContext.Result.GetResultArray();
parameters = expressionContext.Parameters;
foreach (var entityType in entityTypeArray)
{
var isFirst = i == 0; ++i;

Loading…
Cancel
Save