【问题标题】:LINQ to Subsonic Left Outer JoinLINQ to Subsonic 左外连接
【发布时间】:2012-03-05 23:40:14
【问题描述】:

我有以下疑问:

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

【问题讨论】:

    标签: linq linq-to-sql orm subsonic3


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您好,您需要这样做,创建一个 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();
      

      希望这会有所帮助..

      【讨论】:

      • 我搜索了这个问题,这似乎是 Subsonic 中的一个错误
      猜你喜欢
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 2013-09-09
      • 2010-09-21
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多