我正在获取我的数据库列表,选择某些内容,然后我想查询另一个数据库,其中原始列表包含此数据库作业参考
var jobRefs = context.jobs.Where(j => j.LSM_Status == null &&
j.despatched_time == null
)
.Select(x => new { x.job_ref, x.volumes_env, x.postout_deadline , x.UniqNo })
.ToList();
var UpdatedRefs = context.customerslas.Where(c => jobRefs.Any(z=>z.job_ref == c.job_ref) &&
(c.invoiced == 1 ||
c.invoiced == 2) &&
c.active == 1)
.Select(c => c.job_ref)
.ToList();
并得到这个错误
无法创建类型为“匿名类型”的常量值。在此上下文中仅支持原始类型或枚举类型。
第一个查询中的 ToList() 将数据提取到内存中的集合中,而第二个查询中比较数据的位置在数据库中。要解决这个问题,您需要将它们放在同一区域,db 或 memory。
最简单和推荐的方法是从第一个查询中删除 ToList()
var jobRefs = context.jobs.Where(j => j.LSM_Status == null &&
j.despatched_time == null
)
.Select(x => new { x.job_ref, x.volumes_env, x.postout_deadline , x.UniqNo });
var UpdatedRefs = context.customerslas.Where(c => jobRefs.Any(z=>z.job_ref == c.job_ref) &&
(c.invoiced == 1 ||
c.invoiced == 2) &&
c.active == 1)
.Select(c => c.job_ref)
.ToList();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句