public async Task <IList <DepartmentEntity> > Query(DepartmentQueryModel model) { var paging = model.Paging(); var query = Db.Find(m => m.CompanyId == model.CompanyId); var parentId = model.ParentId ?? Guid.Empty; query.Where(m => m.ParentId == parentId); query.WhereIf(model.Name.NotNull(), m => m.Name.Contains(model.Name)); if (!paging.OrderBy.Any()) { query.OrderBy(m => m.Sort); } var joinQuery = query.LeftJoin <UserEntity>((x, y) => x.Leader == y.Id) .LeftJoin <AccountEntity>((x, y, z) => x.CreatedBy == z.Id) .Select((x, y, z) => new { x, LeaderName = y.Name, Creator = z.Name }); var result = await joinQuery.PaginationAsync(paging); model.TotalCount = paging.TotalCount; return(result); }
public async Task <IList <DepartmentEntity> > Query(DepartmentQueryModel model) { var paging = model.Paging(); var query = Db.Find(m => m.ParentId == model.ParentId); query.WhereNotNull(model.Name, m => m.Name.Contains(model.Name)); query.WhereNotNull(model.Code, m => m.Code == model.Code); var joinQuery = query.LeftJoin <AccountEntity>((x, y) => x.CreatedBy == y.Id); if (!paging.OrderBy.Any()) { joinQuery.OrderBy((x, y) => x.Sort); } joinQuery.Select((x, y) => new { x, Creator = y.Name }); var result = await joinQuery.PaginationAsync(paging); model.TotalCount = paging.TotalCount; return(result); }