I have an object which has a property that contains an IEnumerable of objects. Each object in the IEnumerable
has a property that is also an IEnumerable
. I am attempting to capture a larger list of the inner property. Unfortunately, the lambda expression that I am using is returning an OrderedEnumerable
. I'd like to just retrieve a simple IEnumerable
.
public class OrgForm
{
public string OrgNum { get; set; }
public IEnumerable<CustomerForm> CustomerFormList
{
get
{
var list = from cf in OrgCustomerList
where cf.Customer.AssignedOrg == OrgNum
select cf;
return list;
}
}
}
Use of CustomerFormList
OrgForm of = new OrgForm();
IEnumerable<Machine> machines = of.CustomerFormList
.Select(cf => cf.ActiveMachines);
Edit
So after prompting from Jon Skeet and Mark Byers I looked a little deeper and found that ActiveMachines had been modified to perform an OrderBy
so now the return of an OrderedEnumerable
makes sense (my bad for not reading code set change comments).
public class CustomerForm
{
public IEnumerable<Machine> ActiveMachines
{
get
{
var active = Customer.MachineList.ToList()
.Where(m => "a".Equals(m.MachineStatus)
&& !m.ToReapp);
return active.OrderBy(m => m.MachineCategory);
}
}
}
This is great except machines
doesn't allow me to write something like this as it sees each item in machines
as an enumerable based on the category.
foreach (KeyValuePair<int, string[]> kvp in trueUpPt)
{
Machine machine = cf.ActiveMachines
.First(m => m.MachineSk == kvp.Key);
machine.MachineLicenseBillback.ProjectNum = kvp.Value[0];
machine.MachineLicenseBillback.TaskNum = kvp.Value[1];
}