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