I have the following structure.
public class ToolSettings
{
public string Extension { get; set; }
public ObservableCollection<Tool> Tools { get; set; }
}
public class Tool
{
public string Name { get; set; }
public string Command { get set; }
}
public ObservableCollection<ToolSettings> settings { get; set; }
I want to grab the Tools collection from the settings collection, where Extension is equal to a specific line.
Below is my LINQ code, but I only get one item in my collection when I know it more. It looks like it is creating a collection of the collection, so there is only one element.
myListBox.ItemsSource = from i in settings
where i.Extension == myExtension
select i.Tools;
EDIT:
Thanks for all the good (and quick) answers. Turns out I only need the first element, but I know that the SelectMany method will come in handy in the future. So thanks for all the heads. Here is the complete solution I used.
myListBox.ItemsSource = (from i in settings
where i.Extension == myExtension
select i.Tools).First();
source
share