Hi Homer, I thought the query might return all results in the collection where value == 802.11g and Object2 wasn't equal to null. I have so much to learn :) I did a test run and you were right! all objects came back in the collection. I have since implemented your recommendation and that worked :) Here's my test code for ref.
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
List origCollection = new List()
{
new Object1() {ID = 1, theList = new List()
{
new Object2() { Name = "Mode", Value = "802.11b" },
new Object2() { Name = "BW", Value = "20" },
new Object2() { Name = "Chan", Value = "1" },
new Object2() { Name = "Tech", Value = "SISO" }
}
},
new Object1() { ID = 2, theList = new List()
{
new Object2(){ Name = "Mode", Value = "802.11g" },
new Object2(){ Name = "BW", Value = "20" },
new Object2(){ Name = "Chan", Value = "1" },
new Object2(){ Name = "Tech", Value = "SISO" }
}
}
};
var theCollection0 = origCollection.Where(m => m.theList.Select(n => n.Value == "802.11b") != null); // Broken
var theCollection1 = origCollection.Where(m => m.theList.Any(n => n.Value == "802.11b")); // Works!
var theCollection3 = origCollection.Where(m => m.theList.Any(n => n.Value == "802.11z")); // Returns Empty as expected.
}
};
class Object1
{
public int ID { get; set; }
public List theList;
}
class Object2
{
public string Name { get; set; }
public string Value { get; set; }
}
}
Many thanks for spotting and fixing this! your a star :) Br Nigel