Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Using SelectMany to Flatten IQueryable with Nested Objects

$
0
0

I have a LINQ statement that functions correctly, but when I try to export the List<T> to CSV/XLS file, I need to have it flattened so I can traverse through the List<T> and display the headings and values correctly.

My LINQ looks like this:

var itemsToReturn = (from .... my statement .....
select new {
             ProductName = pName,
             AuthorName = authName,
             ProductTypeName = ptName,
             CustomerName = custName,
             CustomerEmail = custEmail,
             Order = order,
             OrderDetails = odetails });


where Order and OrderDetails are classes/entities and the remaining are string type values.  I wish to flatten this so the Order and OrderDetails are at the same level as the other items within 'itemsToReturn'.  I have tried using SelectMany to produce the correct result, but I have not used it before nor can I find examples that are close to my data structure, producing incorrect results or invalid syntax. Thanks for your help.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>