Skip to content

Commit 01fedb3

Browse files
committed
Update BaseRepository.cs
1 parent 4113b5a commit 01fedb3

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

Blog.Core.Repository/BASE/BaseRepository.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,91 @@ public async Task<List<TResult>> QueryMuch<T, T2, T3, TResult>(
453453
return await _db.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).ToListAsync();
454454
}
455455

456+
457+
/// <summary>
458+
/// 两表联合查询-分页
459+
/// </summary>
460+
/// <typeparam name="T">实体1</typeparam>
461+
/// <typeparam name="T2">实体1</typeparam>
462+
/// <typeparam name="TResult">返回对象</typeparam>
463+
/// <param name="joinExpression">关联表达式</param>
464+
/// <param name="selectExpression">返回表达式</param>
465+
/// <param name="whereExpression">查询表达式</param>
466+
/// <param name="intPageIndex">页码</param>
467+
/// <param name="intPageSize">页大小</param>
468+
/// <param name="strOrderByFileds">排序字段</param>
469+
/// <returns></returns>
470+
public async Task<PageModel<TResult>> QueryTabsPage<T, T2, TResult>(
471+
Expression<Func<T, T2, object[]>> joinExpression,
472+
Expression<Func<T, T2, TResult>> selectExpression,
473+
Expression<Func<TResult, bool>> whereExpression,
474+
int intPageIndex = 1,
475+
int intPageSize = 20,
476+
string strOrderByFileds = null)
477+
{
478+
479+
RefAsync<int> totalCount = 0;
480+
var list = await _db.Queryable<T, T2>(joinExpression)
481+
.Select(selectExpression)
482+
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
483+
.WhereIF(whereExpression != null, whereExpression)
484+
.ToPageListAsync(intPageIndex, intPageSize, totalCount);
485+
int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal())).ObjToInt();
486+
return new PageModel<TResult>() { dataCount = totalCount, pageCount = pageCount, page = intPageIndex, PageSize = intPageSize, data = list };
487+
}
488+
489+
/// <summary>
490+
/// 两表联合查询-分页-分组
491+
/// </summary>
492+
/// <typeparam name="T">实体1</typeparam>
493+
/// <typeparam name="T2">实体1</typeparam>
494+
/// <typeparam name="TResult">返回对象</typeparam>
495+
/// <param name="joinExpression">关联表达式</param>
496+
/// <param name="selectExpression">返回表达式</param>
497+
/// <param name="whereExpression">查询表达式</param>
498+
/// <param name="intPageIndex">页码</param>
499+
/// <param name="intPageSize">页大小</param>
500+
/// <param name="strOrderByFileds">排序字段</param>
501+
/// <returns></returns>
502+
public async Task<PageModel<TResult>> QueryTabsPage<T, T2, TResult>(
503+
Expression<Func<T, T2, object[]>> joinExpression,
504+
Expression<Func<T, T2, TResult>> selectExpression,
505+
Expression<Func<TResult, bool>> whereExpression,
506+
Expression<Func<T, object>> groupExpression,
507+
int intPageIndex = 1,
508+
int intPageSize = 20,
509+
string strOrderByFileds = null)
510+
{
511+
512+
RefAsync<int> totalCount = 0;
513+
var list = await _db.Queryable<T, T2>(joinExpression).GroupBy(groupExpression)
514+
.Select(selectExpression)
515+
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
516+
.WhereIF(whereExpression != null, whereExpression)
517+
.ToPageListAsync(intPageIndex, intPageSize, totalCount);
518+
int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal())).ObjToInt();
519+
return new PageModel<TResult>() { dataCount = totalCount, pageCount = pageCount, page = intPageIndex, PageSize = intPageSize, data = list };
520+
}
521+
522+
//var exp = Expressionable.Create<ProjectToUser>()
523+
// .And(s => s.tdIsDelete != true)
524+
// .And(p => p.IsDeleted != true)
525+
// .And(p => p.pmId != null)
526+
// .AndIF(!string.IsNullOrEmpty(model.paramCode1), (s) => s.uID == model.paramCode1.ObjToInt())
527+
// .AndIF(!string.IsNullOrEmpty(model.searchText), (s) => (s.groupName != null && s.groupName.Contains(model.searchText))
528+
// || (s.jobName != null && s.jobName.Contains(model.searchText))
529+
// || (s.uRealName != null && s.uRealName.Contains(model.searchText)))
530+
// .ToExpression();//拼接表达式
531+
//var data = await _projectMemberServices.QueryTabsPage<sysUserInfo, ProjectMember, ProjectToUser>(
532+
// (s, p) => new object[] { JoinType.Left, s.uID == p.uId },
533+
// (s, p) => new ProjectToUser
534+
// {
535+
// uID = s.uID,
536+
// uRealName = s.uRealName,
537+
// groupName = s.groupName,
538+
// jobName = s.jobName
539+
// }, exp, s => new { s.uID, s.uRealName, s.groupName, s.jobName }, model.currentPage, model.pageSize, model.orderField + " " + model.orderType);
540+
456541
}
457542

458543
}

0 commit comments

Comments
 (0)