I have a class structure like below.
ObservableCollection<Group> deviceCollection = new ObservableCollection<Group>();
public class Group
{
public string Name { get; set; }
public List<TargetSelectionStructure> TargetCollection { get; set; }
}
public class TargetSelectionStructure
{
public string ItemId { get; set; }
public string Name { get; set; }
public bool IsGroup { get; set; }
}
From the observable collection object deviceCollection. I need to get the collection which matches with IsGroup property as false. So I have written like
var currentStruct = deviceCollection.Where(d => d.TargetCollection.Any(t => t.IsGroup == false));
Now the currentStruct should contain the collection basically List<TargetSelectionStructure>. I am unable to cast the currentStruct to the type of List<TargetSelectionStructure>.
How can I solve this?
You can’t cast it, because
currentStructis anIEnumerable<Group>.I think you query needs to look like this:
This returns all
TargetSelectionStructureinstances from allGroups that haveIsGroup == false.Your question is not entirely clear. It is possible to interpret your question in a second way: You want to have all
TargetSelectionStructureinstances from aGroupif at least one of them hasIsGroup == false.To achieve this, you would use this query: