I have the following class:
public class OrgAlertList
{
public string CustMailName { get; set; }
/// <summary>
/// Gets all the alerts that apply to this customer.
/// </summary>
public virtual IEnumerable<OrgAlertSummary> Alerts { get; set; }
}
That contains a property (named Alerts) that is an IEnumerable of my second class:
public class OrgAlertSummary
{
/// <summary>
/// Message detailing the alert for the user.
/// </summary>
public string Message { get; set; }
/// <summary>
/// Message detailing how to fix alert.
/// </summary>
public string ActionMessage { get; set; }
}
The Alerts property in the OrgAlertList can contain zero to many OrgAlertSummary items.
I need to write a Lambda expression, or use a LINQ query, to flatten the classes into a new type that has the CustMailName, Message, and ActionMessage in it for each OrgAlertList item where the Alerts property contains at least one OrgAlertSummary item. Can anyone help with this?
Try this: (untested)
Assuming
myOrgAlertListis some sort ofIEnumerable<OrgAlertList>This query will create an anonymous type with fields named CustomMailName, Message, and ActionMessage. If you intend to export this resulting list to other modules, it’s recommended to define your own class and create it in the select instead of using an anonymous type.