此查询正在编译且没有错误:
var _entityList = context.customer
.Join(context.applications,
cust => cust.cust_id,
app => app.cust_id,
(cust, app) => new { customer = cust, application = app })
.Join(context.advices,
cust => cust.application.app_id,
sa => sa.app_id,
(cust, sa) => new { customer = cust, advice = sa })
.GroupBy(g => new { g.customer.customer.cust_id, g.customer.customer.cust_code, g.customer.customer.cust_name })
.Select(g => new { cust_id = g.Key.cust_id, cust_code = g.Key.cust_code, cust_name = g.Key.cust_name })
.ToList();
向上述查询添加条件 where 子句时会返回编译时类型转换错误:
var _entityList = context.customer
.Join(context.applications,
cust => cust.cust_id,
app => app.cust_id,
(cust, app) => new { customer = cust, application = app })
.Join(context.advices,
cust => cust.application.app_id,
sa => sa.app_id,
(cust, sa) => new { customer = cust, advice = sa });
if (custcode != null && custcode != "")
_entityList = _entityList.Where(e => e.customer.customer.cust_code == custcode);
_entityList = _entityList
.GroupBy(g => new { g.customer.customer.cust_id, g.customer.customer.cust_code, g.customer.customer.cust_name })
.Select(g => new { cust_id = g.Key.cust_id, cust_code = g.Key.cust_code, cust_name = g.Key.cust_name })
.ToList(); // error on this line
无法将类型隐式转换System.Collections.Generic.List<AnonymousType#1>
为System.Linq.IQueryable<AnonymousType#2>
我错过了什么?