0
我有如下功能:删除从集合项实体框架
IEnumerable<Group> GetAllChildren(int parentID)
{
using (Entities db = new Entities())
{
var result = (from x in db.Groups
where x.ParentID == parentID
select x).ToList();
foreach (Group child in result.ToList())
{
result.AddRange(GetAllChildren(child.GroupID));
}
return result;
}
}
在上面的函数,如果我通过一组名字,我让所有的孩子们在所有的水平。 它按预期工作。
现在我的查询看起来是这样的:
GroupNamesWithCorrespondingEffects
= new ObservableCollection<GroupNameWithCorrespondingEffect>
(from g in db.Groups
select new GroupNameWithCorrespondingEffect
{
GroupID = g.GroupID,
GroupName = g.GroupName,
CorrespondingEffect = g.Master_Effects.Effect
}
);
上面的查询会给我所有的群体。
现在我想从GroupNamesWithCorrespondingEffects
中删除group with id == 25
的孩子的所有组。
我在第二个查询中尝试过.Remove(GetAllChildren(25))
。但我得到以下错误。
Collection.Remove(GroupNameWithCorrespondingEffect)有一些无效参数。
感谢它完美的作品。 – Vishal