2012-03-05 237 views
0

我有以下查询:LINQ到亚音速左外连接

var q = from x in content_item.All() 
     join y in vendor.All() on x.Vendor_ID equals y.Vendor_ID into tmp 
     from v in tmp.DefaultIfEmpty() 
     select new { Z=x.Content_Item_Name,W=((v!=null)?v.Vendor_Name:"")}; 
当我输入

var items = q.ToList(); 

我有以下异常:

Expression of type 'System.Collections.Generic.IEnumerable`1[Vamp.Models.content_item]' cannot be used for parameter of type 'System.Linq.IQueryable`1[Vamp.Models.content_item]' of method 'System.Linq.IQueryable`1[<>f__AnonymousType0`2[Vamp.Models.content_item,System.Collections.Generic.IEnumerable`1[Vamp.Models.vendor]]] GroupJoin[content_item,vendor,Nullable`1,<>f__AnonymousType0`2](System.Linq.IQueryable`1[Vamp.Models.content_item], System.Collections.Generic.IEnumerable`1[Vamp.Models.vendor], System.Linq.Expressions.Expression`1[System.Func`2[Vamp.Models.content_item,System.Nullable`1[System.UInt32]]], System.Linq.Expressions.Expression`1[System.Func`2[Vamp.Models.vendor,System.Nullable`1[System.UInt32]]], System.Linq.Expressions.Expression`1[System.Func`3[Vamp.Models.content_item,System.Collections.Generic.IEnumerable`1[Vamp.Models.vendor],<>f__AnonymousType0`2[Vamp.Models.content_item,System.Collections.Generic.IEnumerable`1[Vamp.Models.vendor]]]])' 

任何想法?

注:content_item.All()是IQueryable的和vendor.All()是IQueryable的

回答

1

对不起,我错过了这个当你问这个问题时...

SubSonic 3中的左外连接语法稍有不同。我有一个解决方法发布为这个问题的答案:Subsonic 3.0 Left Join

+0

它的工作原理,谢谢。 – 2012-04-07 20:56:19

0

嗨,你需要做这样的事情,创造一个getter setter方法如下:

public class ReturnProperty 
{ 
     public string Z{ get; set; } 
     public string W{ get; set; } 

} 

而变化您的查询是这样的:

var q = from x in content_item.All() 
       join y in vendor.All() on x.Vendor_ID equals y.Vendor_ID into tmp 
       from v in tmp.DefaultIfEmpty() 
       select new ReturnProperty { Z=x.Content_Item_Name,W=((v!=null)?v.Vendor_Name:"")}; 
var items = q.ToList(); 

希望这有助于..

+0

对不起,但不行! – 2012-03-06 15:10:03

+1

我搜索了这个问题,它似乎是亚音速的一个错误 – 2012-03-07 08:42:45