?業(yè)務service.cs中ListFilter方法中內(nèi)容
//反向遞歸查詢部門列表
List<DepartmentEntity> departmentList = await departmentService.GetReverseRecurrenceList(new DepartmentListParam() { Ids = operatorInfo.DepartmentId.ToString() });
if (departmentList != null && departmentList.Count > 0)
{
//查找列表中為根節(jié)點的部門
DepartmentEntity department = departmentList.Find(a => a.ParentId == 0);
if (department != null)
{
strSql.Append(" AND a.AffiliatedUnit = @AffiliatedUnit");
parameter.Add(DbParameterExtension.CreateDbParameter("@AffiliatedUnit", department.Id));
}
}
DepartmentService.cs中內(nèi)容文章來源:http://www.zghlxwxcb.cn/news/detail-727059.html
public async Task<List<DepartmentEntity>> GetReverseRecurrenceList(DepartmentListParam param)
{
var strSql = new StringBuilder();
List<DbParameter> filter = ListFilter(param, strSql);
var list = await this.BaseRepository().FindList<DepartmentEntity>(strSql.ToString(), filter.ToArray());
return list.ToList();
}
private List<DbParameter> ListFilter(DepartmentListParam param, StringBuilder strSql, bool bNewsContent = false)
{
//param.ids需為單個ID
strSql.Append($@"with temp as
( select * from SysDepartment where id = {(!string.IsNullOrEmpty(param.Ids) ? param.Ids : "0")}
union all select a.* from SysDepartment a inner join temp on temp.[parentId] = a.[id])
select * from temp");
var parameter = new List<DbParameter>();
//strSql.Append(@" ORDER BY cast(ISNULL(BuildingNumber, '0') as int) asc,cast(ISNULL(Floor, '0') as int) asc,HouseCode asc ");
return parameter;
}
mysql數(shù)據(jù)庫中參考mysql 遞歸語法修改sql文章來源地址http://www.zghlxwxcb.cn/news/detail-727059.html
到了這里,關(guān)于【.net core】yisha框架 SQL SERVER數(shù)據(jù)庫 反向遞歸查詢部門(子查父)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!