2012-07-12 26 views
2

即時通訊「方法'加入'不支持」錯誤...有趣的是,我只是將第一個LINQ轉換成第二個版本,它不工作...客戶關係管理LINQ複合連接「方法'加入'不支持」錯誤

什麼,我想有是LINQ#3型,但它也不起作用......


這工作

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 
}; 

STIL不起作用

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 
}; 

但即時只是試圖做這裏的例子(S)How to do joins in LINQ on multiple fields in single join

我在想什麼?

在此先感謝

+0

在你給第四樣品,你可以刪除'新{富='和'}'在加入並看看它是否有效? – 2012-07-13 01:37:37

回答

1

雖然我不能完全確定你使用的CRM,我想你誤解的東西。 爲了使LINQ查詢正常工作,需要有一個LINQ提供程序用於底層數據源 - 負責翻譯鏈的鏈接的代碼位。 JoinWhere,操作員使用等等,到數據源的查詢API中。這可能是SQL,一些自定義查詢語言或一些方法鏈。

兩個LINQ提供者(例如LINQ to DataSet和你自己編寫的一些自定義提供者)不需要支持相同的方法和其他代碼。 LINQ提供者支持的LINQ方法(和/或其他嵌入語句)的精確子集取決於其實現。

這樣看來,你使用的LINQ提供程序似乎並不理解使用多個字段的連接的標準語法,或者似乎並不理解匿名類型在所有。

我的建議是搜索提供的LINQ提供程序的文檔,以查看它支持哪些查詢操作(也許有關於不支持此特定查詢模式的註釋)。否則,你將不得不求助於某種其他查詢 - 一個不涉及equijoin。也許你最好的選擇是分別執行連接,然後相交兩個結果組。這真的取決於案件的具體情況。

1

你看過MSDN samples。有一些多列連接的例子有:

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); 
} 
} 

This other thread可能是相關的

相關問題