函数 SqlFunc.AggregateDistinctCount 无法获取到对应数量 返回
使用以下两种方式ExtendAttr属性都无法获取到值,但是通过执行的sql直接到数据库中又可以拿到数据。
并且神奇的是直接拿完整数据却只能拿到4条(设想是应该又N条数据)。
用法一:
var testPapers = _db.Queryable<TestPaper_Info>()
.WhereIF(queryModel.SubjectType > Common.Zore, x => x.SubjectType == queryModel.Type)
.WhereIF(queryModel.GradeNo > Common.Zore, x => x.GradeNo == queryModel.GradeNo)
.WhereIF(queryModel.Year > Common.Zore, x => x.Year == queryModel.Year)
.Select(x => x)
.MergeTable();
var asss = await _db.Queryable<System_Type>()
.InnerJoin<System_Enum>((st, se) => st.Key == SystemTypeKeyConst.TestPaperType && st.Id == se.Type)
.LeftJoin(testPapers, (st, se, ti) => se.KeyId == ti.Type)
.OrderByDescending((st, se, ti) => se.Order)
.GroupBy((st, se, ti) => se.KeyId)
.Select((st, se, ti) => new KeyValueModel
{
Key = se.KeyId.ToString(),
Value = se.Name,
ExtendAttr = SqlFunc.AggregateDistinctCount(ti.Id).ToString(),
})
.ToListAsync();
用法二:
var asdsd = Expressionable.Create<System_Type, System_Enum, TestPaper_Info>()
.And((st, se, ti) => st.Key == SystemTypeKeyConst.TestPaperType && st.Id == se.Type)
.And((st, se, ti) => se.KeyId == ti.Type)
.AndIF(queryModel.SubjectType > Common.Zore, (st, se, ti) => ti.SubjectType == queryModel.Type)
.AndIF(queryModel.GradeNo > Common.Zore, (st, se, ti) => ti.GradeNo == queryModel.GradeNo)
.AndIF(queryModel.Year > Common.Zore, (st, se, ti) => ti.Year == queryModel.Year);
var asss = await _db.Queryable<System_Type>()
.InnerJoin<System_Enum>((st, se) => st.Key == SystemTypeKeyConst.TestPaperType && st.Id == se.Type)
.LeftJoin<TestPaper_Info>(asdsd.ToExpression())
.OrderByDescending((st, se, ti) => se.Order)
.GroupBy((st, se, ti) => se.KeyId)
.Select((st, se, ti) => new KeyValueModel
{
Key = se.KeyId.ToString(),
Value = se.Name,
ExtendAttr = SqlFunc.AggregateDistinctCount(ti.Id).ToString(),
})
.ToListAsync();
调试
数据库sql 执行:
不分组取完整数据: