2013-10-24 104 views
0

我试图做一个linq GroupJoin,并且我收到前面提到的错误。这是代码参数的类型不能被推断使用Linq GroupJoin

public Dictionary<string, List<QuoteOrderline>> GetOrderlines(List<string> quoteNrs) 
{ 
    var quoteHeadersIds = portalDb.nquote_orderheaders 
     .Where(f => quoteNrs.Contains(f.QuoteOrderNumber)) 
     .Select(f => f.ID).ToList(); 

    List<nquote_orderlines> orderlines = portalDb.nquote_orderlines 
     .Where(f => quoteHeadersIds.Contains(f.QuoteHeaderID)) 
     .ToList(); 

    var toRet = quoteNrs 
     .GroupJoin(orderlines, q => q, o => o.QuoteHeaderID, (q => o) => new 
     { 
      quoteId = q, 
      orderlines = o.Select(g => new QuoteOrderline() 
      { 
       Description = g.Description, 
       ExtPrice = g.UnitPrice * g.Qty, 
       IsInOrder = g.IsInOrder, 
       PartNumber = g.PartNo, 
       Price = g.UnitPrice, 
       ProgramId = g.ProgramId, 
       Quantity = (int)g.Qty, 
       SKU = g.SKU 
      }).ToList() 
     });   
} 

回答

0

我怀疑这是眼前的问题:

(q => o) => new { ... } 

我怀疑你的意思是:

(q, o) => new { ... } 

换句话说,“这里是正在查询的功能和订单,并返回一个匿名类型“。第一种语法根本没有意义 - 即使考虑更高级的函数,通常也会有q => o => ...而不是(q => o) => ...

现在单靠它自己就不够了......因为GroupJoin没有返回字典。 (的确,您甚至还没有return声明。)之后您将需要拨打ToDictionary。或者,最好通过ToLookup返回ILookup<string, QuoteOrderLine>

+0

感谢您的快速回复,实际上这是我帐户上的错字。我做了ToDictionary调用,但错误仍然没有修复。同样的错误。 –

+0

我发现了其余的bug:我试图加入基于不同类型键的列表。 –

相关问题