【问题标题】:LINQ error with ToListToList 的 LINQ 错误
【发布时间】:2011-12-29 21:14:13
【问题描述】:

我有这个问题:

(from r in gServiceContext.CreateQuery("opportunity")
    join c in gServiceContext.CreateQuery("contact") on ((EntityReference)r["new_contact"]).Id equals c["contactid"]
    join n in gServiceContext.CreateQuery("annotation") on r["opportunityid"] equals ((EntityReference)n["objectid"]).Id into opp
    from o in opp.DefaultIfEmpty().ToList()
    where ((EntityReference)r["new_channelpartner"]).Id.Equals(lProfileProperty.PropertyValue) && ((OptionSetValue)r["new_leadstatus"]).Equals("100000002")

使用 ToList() 我收到此错误:

方法'GroupJoin'不能跟随方法'Join'或者不是 支持的。尝试根据支持的方法编写查询或调用 调用不支持之前的“AsEnumerable”或“ToList”方法 方法。

如果我关闭 ToList,我会得到同样的错误。有没有办法解决这个问题,还是我做错了?

谢谢!

旁注:我使用的是 DefaultIfEmpty,因为即使它加入的记录为 NULL,我仍需要它来下拉记录。

【问题讨论】:

    标签: c# linq


    【解决方案1】:

    你没有使用你的分组,所以这应该可以工作:

    (from r in gServiceContext.CreateQuery("opportunity")
        join c in gServiceContext.CreateQuery("contact") on ((EntityReference)r["new_contact"]).Id equals c["contactid"]
        join n in gServiceContext.CreateQuery("annotation") on r["opportunityid"] equals ((EntityReference)n["objectid"]).Id
        where ((EntityReference)r["new_channelpartner"]).Id.Equals(lProfileProperty.PropertyValue) && ((OptionSetValue)r["new_leadstatus"]).Equals("100000002")
    

    改变

    join c in gServiceContext.CreateQuery("contact")
    

    join c in gServiceContext.CreateQuery("contact").DefaultIfEmpty()
    

    【讨论】:

    • 谢谢,这在大多数情况下都有效。没有错误,但我有 DefaultIfEmpty 因为联系人中的某些记录有空记录,如果加入的记录为空,我仍想将它们拉出来。这个查询有可能吗?
    猜你喜欢
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多