Make a new Linq Select. Several extension methods

dynamic-linq linq linq-to-objects

Question

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.

1
0
7/22/2010 7:44:41 PM

Popular Answer

It was getting the wrong definition. Actual error when on right definition: Cannot convert lambda expression to type 'System.Linq.IQueryable' because it is not a delegate type

0
7/28/2010 10:08:42 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow