创建新的 Linq SelectMany 扩展方法
我正在使用 Linq.Dynamic。我已经向 all 添加了另一个 SelectMany 扩展,用于使用数据创建新的匿名对象。但是,我遇到了另一个我似乎无法解决的问题。
我想要按如下方式链接扩展方法,但使用动态方法:
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
});
理想情况下,我想按如下方式链接动态 SelectMany:
db.Customers.SelectMany(c => c.Orders.SelectMany("Order_Details", "new(outer.OrderID, inner.UnitPrice)"), "new(outer.CustomerID, inner.OrderID)");
或有影响的东西。问题是我无法获得匹配的签名。
我尝试了许多不同的选项来让它允许链接。但它就是行不通。我认为理想情况下它看起来像这样:
public static IQueryable SelectMany(this IQueryable source, IQueryable innerExpression, string resultsSelector, params object[] values)
但是,它不识别 c => c. 订单为 IQueriable。我还需要弄清楚如何对结果执行 DefaultIfEmpty 以允许 LEFT JOIN。
请帮忙。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
c.Orders
是一个 EntitySet。 EntitySet 不实现 IQueryable。尝试c.Orders.AsQueryable()c.Orders
is an EntitySet. EntitySet doesn't implement IQueryable. Tryc.Orders.AsQueryable()
它得到了错误的定义。正确定义时的实际错误:无法将 lambda 表达式转换为类型“System.Linq.IQueryable”,因为它不是委托类型
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