我有一个表“Components”,其中包含列“AssemblyGuid”和“PartGuid”。 我有一个组件列表“componentsGuids”
var componentsGuids = _input.Select(x =>
new Component
{
AssemblyGuid = x.AssemblyGuid,
PartGuid = x.DetailGuid,
}).ToList();
如何进行 Linq To Sql 查询以通过复合键加载“componentsGuids”列表中的所有组件条目?
var componentsDb = Context.Components//.ToList() an error occurs here
.Where(
x => componentsGuids.Any(
y => y.AssemblyGuid == x.AssemblyGuid
&& y.PartGuid == x.PartGuid));
最佳答案
也许这可以帮助您找到解决方案。我不确定代码是否像开箱即用的那样工作,但我希望它能使这个想法清晰。在列表中连接您的两个 guid,并使用 Contains
来检查也连接的 guid 对是否存在。
类似的东西应该可以工作:
var componentsGuidsConcat = componentsGuid
.Select(p => AssemblyGuid.ToString() + PartGuid.ToString())
.ToList();
var componentsDb = Context.Components
.Where(p => componentsGuidsConcat.Contains(
p.AssemblyGuid.ToString() + p.PartGuid.ToString())
);
关于c# - 在此上下文中仅支持原始类型或枚举类型。链接到 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49813651/