Linq Help

Hi All,

I have an object that has several parameters. One of the parameters is array of another class that has its own parameters.

Here is a stripped down definition:

public class Project
{
public string Name { get; set; }
public Customfield[] CustomFields { get; set; }
}

public class Customfield
{
public string Name { get; set; }
public string[] Values { get; set; }
}

I also have an array that contains one or more Project.

I am trying to use Linq to find the Project that has a particular value in one of the Customfields. The values in this Customfield are unique.
First, is this possible?
Here is my attempt that did not work.
j.Projects.Where(p => p.CustomFields.Where(pl => pl.Name == “Location”).FirstOrDefault().Values[0].Trim().Equals(jobnum.Trim())).FirstOrDefault();

I had the wrong customfield name (just in case someone noticed) but that still didn’t matter.

So I’m thinking that you cannot next Where clauses as I was trying to do.

Joe Rojas
Epicor Application Manager
Nordson MEDICAL
+1.508.597.1392
Phone+1.774.826.9245 Mobile

Try:

var myChildRecs = j.Projects.SelectMany(p => p.CustomFields).Where(pl => pl.Name == “Location”);