ToList的LINQ错误

时间:2011-12-29 21:14:13

标签: c# linq

我有这个问题:

(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,我仍需要它来记录记录。

1 个答案:

答案 0 :(得分: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()
相关问题