Queryable 查询 select 组装新对象后 orderby 内的对象有二义性 BUG 返回

C#论坛 老数据
2210

版本: .net  5.0.0.8

 var list = db.Db.Queryable<AgentTwo>()

                .Where(exp)

                .Select(at => new {

                    AgentTwoId = at.AgentTwoId,

                    Name = at.Name,

                    No = at.No,

                    Address = at.Address,

                    Owner = at.Owner,

                    Phone = at.Phone,

                    CanTakeWine = SqlFunc.Subqueryable<MonthTwo>()

                        .Where(ms => ms.TwoId == at.AgentTwoId && ms.Getmonth < new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1))

                        .Select(ms1 => SqlFunc.AggregateSum((ms1.Getnum - ms1.Takennum) / 12))

                }).OrderBy(md => md.CanTakeWine)

                .ToPageList(page, size, ref count);

这里 VS IDE 环境识别到的 md 这个对象是指 select 内重从新组装后的对象 

{ AgentTwoId,Name,No,Address,Owner,Phone,CanTakeWine} 这个,但是实际运行后报错提示 CanTakeWine 未定义。

估计是源码内识别的 AgentTwo 这货。


那这里就有二义性了:如果 orderyby 放在 where 后 select 前指代 AgentTwo 没疑问,但是放在select 后就有二义性了。

image.png


image.png


热忱回答0