我有一个这样的课程:
public class Item
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private bool isAction1Possible;
public bool IsAction1Possible
{
get { return isAction1Possible; }
set { isAction1Possible = value; }
}
private bool isAction2Possible;
public bool IsAction2Possible
{
get { return isAction2Possible; }
set { isAction2Possible = value; }
}
private bool isAction1Selected;
public bool IsAction1Selected
{
get { return isAction1Selected; }
set
{
if(IsAction2Selected)
IsAction2Selected = false;
isAction1Selected = value;
}
}
private bool isAction2Selected;
public bool IsAction2Selected
{
get { return isAction2Selected; }
set
{
if(IsAction1Selected)
IsAction1Selected = false;
isAction2Selected = value;
}
}
private Dictionary<int, Item> dependencies = new Dictionary<int, Item>();
public Dictionary<int, Item> Dependencies
{
get { return dependencies; }
set { dependencies = value; }
}
}
Dependencies
Dictionary
包含Items
类的实例。
我现在有一个List
,其中我添加了Items
或IsAction1Possible
为IsAction2Possible
的所有true
,其中正在呈现给用户。用户现在选择他想要进一步处理的项目,这会将IsActionXSelected
属性设置为true
。
最后,我想使用Lambda查询来接收List
IsAction1Possible
为true
且IsAction1Selected
为true
的所有“基础”项目} {strong}和{/ strong> Items
Dependencies
Dictionary
IsAction1Possible
中的所有true
。
我能够使用Select
或使用SelectMany
的所有依赖关系项接收所有基本项。
这是我尝试的但我最终只得到了基本项而不是依赖项。甚至可以在一个查询中执行它我将不得不为Base项目做一个而对依赖项做一个?谢谢你的任何提示!
IEnumerable<Item> toBeProcessed = ItemsAction1Enabled
.Where(i => i.IsAction1Possible == true && i.IsAction1Selected == true).ToList()
.SelectMany(d => d.Dependencies.Values)
.Where(d => d.Action1Possible == true);