- 当业务表导出时,需要额外添加关联表数据,
SQL
语句关联查询并拼接比较麻烦
- 框架是通过扩展
Database
的QueryPageAsync
方法的参数来实现
class TestRepository
{
internal static Task<PagingResult<TbTest>> QueryTestsAsync(Database db, PagingCriteria criteria)
{
var sql = "";
// 导出关联表信息
List<Test> datas = []; // 查询关联表数据
if (criteria.ExportMode != ExportMode.None)
{
datas = await db.QueryListAsync<Test>(d => d.CompNo == db.User.CompNo);
// 添加导出附加栏位
criteria.ExportColumns.Add(new ExportColumnInfo
{
Id = "Test",
Name = "测试",
IsAdditional = true // 标记为附加栏位
});
}
return db.QueryPageAsync<TbTest>(sql, criteria, (d, c) =>
{
if (c.Id == "Test" && d.IsTest) // 判断附加栏位的条件
{
var tests = datas?.Where(a => a.HeadId == d.Id);
return string.Join(Environment.NewLine, tests?.Select(a => a.Name));
}
return string.Empty;
});
}
}