什么是 "unable to create a constant value of type ''. only primitive types or enumeration types are supported in this context."

What is "unable to create a constant value of type ''. only primitive types or enumeration types are supported in this context."

WaiverID 是一个 int,所以我不确定所讨论的非原始类型是什么。

 var originalWaivers = _context.SurchargeWaivers
.Where(x => updatedWaivers.Select(waiver => waiver.WaiverID).Contains(x.WaiverID));

我正在尝试在数据库中查询原始实体,以便更新它们。

更新: 更具体地说,为什么这是一个问题。为什么列表可以工作但 IEnumerable 是个问题?

好像是updatedWaivers的问题。无需对每个项目执行内部查询,只需将 id 存储到 List 中并使用它:

var idList = updatedWaivers.Select(waiver => waiver.WaiverID).ToList();
var originalWaivers = _context.SurchargeWaivers
                              .Where(x => idList.Contains(x.WaiverID));