2019-11-10 [低级错误]
_provider.vw_order_stages_work_count.AsNoTracking().GroupBy(x => x.stage).ToList()
注:该语句可以正常的执行,不会报错;产生的问题是表自身关联查询,数据量倍增
暂时这样子修改,会按stage分组,数据量正常,暂时还没研究这样子是否存在性能问题
//视图数据全部需要所以直接ToList,减少查询数据库的交互
_provider.vw_order_stages_work_count.AsNoTracking().ToList();
qry.GroupBy(x => x.stage);
2019-11-20
正确写法:
EF 查询直接使用 IQueryable<T> 在select中new 对象会抛出异常,需要转为 IEnumerable<T> 在select中才可以new 新的复杂对象,既需要将最终数据载入到内存中操作,据说是 EF 在查询中无法知道new 的新对象与实体的映射关系(注:感觉这个说法不太正确)
private IEnumerable<T> FormatProductProcessDayOutputData<T>(IEnumerable<T> qry) where T : vw_ProductProcess_DayOutputData, new()
{
var list = qry.Select(x => new T
{
is_social_security_card = x.is_social_security_card == "1" ? "社保" : "非社保"
});
return list;
}