Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CRM LINQ复合联接“不支持方法“联接”错误_C#_Linq_Dynamics Crm_Crm - Fatal编程技术网

C# CRM LINQ复合联接“不支持方法“联接”错误

C# CRM LINQ复合联接“不支持方法“联接”错误,c#,linq,dynamics-crm,crm,C#,Linq,Dynamics Crm,Crm,我正在获取一个不支持“Join”方法的错误。。。有趣的是,我只是将第一个LINQ转换为第二个版本,但它不起作用 var query_join9 = from s in orgSvcContext.CreateQuery<ServiceAppointment>() join b in orgSvcContext.CreateQuery<bh_product>() on new { foo = s.bh_contract.Id } equals new { foo = b.b

我正在获取一个不支持“Join”方法的错误。。。有趣的是,我只是将第一个LINQ转换为第二个版本,但它不起作用

var query_join9 = from s in orgSvcContext.CreateQuery<ServiceAppointment>()
join b in orgSvcContext.CreateQuery<bh_product>()
on new { foo = s.bh_contract.Id }
equals new { foo = b.bh_Contract.Id }
where s.bh_contract.Id == Guid.Parse("09BDD5A9-BBAF-E111-A06E-0050568B1372")
select new
{
Events = s,
Products = b
};
我想要的是LINQ版本3,但它也不起作用

var query_join9 = from s in orgSvcContext.CreateQuery<ServiceAppointment>()
join b in orgSvcContext.CreateQuery<bh_product>()
on new { foo = s.bh_contract.Id }
equals new { foo = b.bh_Contract.Id }
where s.bh_contract.Id == Guid.Parse("09BDD5A9-BBAF-E111-A06E-0050568B1372")
select new
{
Events = s,
Products = b
};
这很有效

var query_join9 = from s in orgSvcContext.CreateQuery(ServiceAppointment.EntityLogicalName)
join b in orgSvcContext.CreateQuery(bh_product.EntityLogicalName)
on s["bh_contract"] equals b["bh_contract"]
where ((EntityReference)s["bh_contract"]).Id == Guid.Parse("09BDD5A9-BBAF-E111-A06E-0050568B1372")
select new
{
Events = s,
Products = b
};
这并不重要

var query_join9 = from s in orgSvcContext.CreateQuery(ServiceAppointment.EntityLogicalName)
join b in orgSvcContext.CreateQuery(bh_product.EntityLogicalName)
on new { contractid = s["bh_contract"] }
equals new { contractid = b["bh_contract"] }
where ((EntityReference)s["bh_contract"]).Id == Guid.Parse("09BDD5A9-BBAF-E111-A06E-0050568B1372")
select new
{
Events = s,
Products = b
};
而且,这不是,这是一个复合连接,也是我真正的目标

var query_join9 = from s in orgSvcContext.CreateQuery(ServiceAppointment.EntityLogicalName)
join b in orgSvcContext.CreateQuery(bh_product.EntityLogicalName)
on new { contractid = s["bh_contract"], serviceid = s["serviceid"] }
equals new { contractid = b["bh_contract"], serviceid = s["serviceid"] }
where ((EntityReference)s["bh_contract"]).Id == Guid.Parse("09BDD5A9-BBAF-E111-A06E-0050568B1372")
select new
{
Events = s,
Products = b
};
我尝试了早期绑定,但仍然不起作用

var query_join9 = from s in orgSvcContext.CreateQuery<ServiceAppointment>()
join b in orgSvcContext.CreateQuery<bh_product>()
on new { foo = s.bh_contract.Id }
equals new { foo = b.bh_Contract.Id }
where s.bh_contract.Id == Guid.Parse("09BDD5A9-BBAF-E111-A06E-0050568B1372")
select new
{
Events = s,
Products = b
};
还是不行

var query_join9 = from s in orgSvcContext.CreateQuery<ServiceAppointment>()
join b in orgSvcContext.CreateQuery<bh_product>()
on new { s.bh_contract.Id, s.ServiceId }
equals new { b.bh_Contract.Id, ServiceId = b.bh_Service }
where s.bh_contract.Id == Guid.Parse("09BDD5A9-BBAF-E111-A06E-0050568B1372")
select new
{
Events = s,
Products = b
};
但我只是想做这里的例子

我错过了什么


提前感谢

虽然我不完全确定您使用的是哪种CRM,但我认为您误解了什么。 为了使LINQ查询能够工作,需要为基础数据源提供LINQ提供程序—负责将连接、位置、运算符使用等链转换为数据源的查询API的代码位。这可能是SQL、某些自定义查询语言或某些方法链

两个LINQ提供程序(例如,一个用于LINQtoDataSet的提供程序和一些您自己编写的自定义提供程序)不必支持相同的方法和其他代码。LINQ提供程序支持的LINQ方法和/或其他嵌入式语句的精确子集取决于其实现

这样来看,您使用的LINQ提供程序似乎不理解使用多个字段的联接的标准语法,或者根本不理解匿名类型的用法,这并不奇怪

我的建议是搜索所提供的LINQ提供程序的文档,看看它支持哪些查询操作。可能有一个关于不支持这种特定查询模式的注释。如果做不到这一点,您将不得不求助于其他类型的查询——一个不涉及equijoin的查询。也许最好的选择是分别执行连接,然后将两个结果组相交。这真的取决于案件的具体情况。

您是否查看了该案例。这里有一些多列联接示例:

using (ServiceContext svcContext = new ServiceContext(_serviceProxy))
{
 var list_join = (from a in svcContext.AccountSet
                  join c in svcContext.ContactSet
                  on a.PrimaryContactId.Id equals c.ContactId
                  where a.Name == "Contoso Ltd" &&     <<--- multiple join here
                  a.Address1_Name == "Contoso Pharmaceuticals"
                  select a).ToList();
 foreach (var c in list_join)
 {
  System.Console.WriteLine("Account " + list_join[0].Name
      + " and it's primary contact "
      + list_join[0].PrimaryContactId.Id);
 }
}

可能是相关的

在您给出的第4个示例中,能否删除join中的新{foo=and}并查看它是否有效?