I am using Linq.Dynamic. I have already added another SelectMany extension to all for creating a new anonymous object with the data. But, I have ran into another issue that I can not seem to solve.
I want to have extension method chaining as follows, but using the dynamic methods:
var customerandorderflat = db.Customers
.SelectMany(c => c.Orders.SelectMany(o => o.Order_Details,
(ord, orddetail) => new
{
OrderID = ord.OrderID,
UnitPrice = orddetail.UnitPrice
}).DefaultIfEmpty(),
(cus, ord) => new
{
CustomerId = cus.CustomerID,
CompanyName = cus.CompanyName,
OrderId = ord.OrderID == null ? -1 : ord.OrderID,
UnitPrice = ord.UnitPrice
});
Ideally I would like to chain the dynamic SelectMany as follows:
db.Customers.SelectMany(c => c.Orders.SelectMany("Order_Details", "new(outer.OrderID, inner.UnitPrice)"), "new(outer.CustomerID, inner.OrderID)");
Or something to that affect. The problem is that I can not get a signature to match.
I have tried many different options to get it to allow chaining. But it just doesn't work. I am thinking ideally it would look like this:
public static IQueryable SelectMany(this IQueryable source, IQueryable innerExpression, string resultsSelector, params object[] values)
But, it doesn't recognize c => c.Orders as IQueriable. I also need to figure out how to do DefaultIfEmpty on the results to allow for LEFT JOINs.
Please help.