动态 CRM 2011 - LINQ - 检索客户和联系人之间的连接



我已经做了很多搜索,找不到一个示例来说明如何在Dynamics CRM 2011中检索AccountContact之间的Connection信息。有人可以指出我正确的方向吗?

仅供参考,这是我检索数据的常用方法(它不包括此问题,我尝试过的任何方法都没有接近工作)

        var context = new XrmServiceContext(crmService);
        var accounts = context.AccountSet.Where(a => a.Name.StartsWith("A"));
        Console.WriteLine("Accounts beginning with the letter A");
        foreach (Account account in accounts)
        {
            Console.WriteLine("{0} ({1})", account.Id, account.Name);
        }

提前谢谢。

编辑:更新答案以匹配要求。

连接的详细信息存储在连接实体集中。

var context = new XrmServiceContext(crmService);
var accounts = context.AccountSet.Where(a => a.Name.StartsWith("A"));
Console.WriteLine("Accounts beginning with the letter A");
foreach (Account account in accounts)
{
    Console.WriteLine("{0} ({1})", account.Id, account.Name);
    var accToConConnections = 
    context.ConnectionSet.Where(con => con.Record1Id.Id.Equals(account.Id) &&
                                       con.Record2ObjectTypeCode.Value.Equals((int)Contact.EntityTypeCode));
   //do something with the connections if you want!
}

回答了我自己的问题。MSDN中埋藏着一个例子,谷歌从它的搜索结果中省略了它。MSDN 示例

相关内容

最新更新