我有两个LINQ查询如下:合并两个查询在LINQ
GroupNamesWithCorrespondingEffects
= new ObservableCollection<GroupNameWithCorrespondingEffect>(
from g in db.Groups
select new GroupNameWithCorrespondingEffect
{
GroupID = g.GroupID,
GroupName = g.GroupName,
CorrespondingEffect = g.Master_Effects.Effect
}
);
GroupNamesWithCorrespondingEffects
= new ObservableCollection<GroupNameWithCorrespondingEffect>
(GroupNamesWithCorrespondingEffects.
Where(u => !GetAllChildren(25).
Select(x => x.GroupID).
Contains(u.GroupID)).ToList());
现在,我怎么合并这两个查询?
我已经试过你的答案以及尼尔的其他答案。在这两种情况下,我得到以下错误:'LINQ to Entities无法识别'System.Collections.Generic.IEnumerable'1 [WPF_Client.HelperClasses.GroupNameWithCorrespondingEffect] GetAllChildren(Int32)'方法,并且此方法无法翻译' – Vishal
好的,EF无法撰写,因为我怀疑。它应该像提取GetAllChildren(25)一样简单。在变量中选择(x => x.GroupID).ToList()并使用该变量来执行Contains。如果那个引发同样的问题,你可以拿Neil的答案,并在.Where调用之前添加一个ToList()。第二部分将在内存中运行,但它与您在代码中所做的无关。 – Wasp
感谢您解释这一行:'第二部分将在内存中运行,但它与您在代码中所做的没有什么不同。“同时感谢您的回答。 – Vishal