CRM 2011对象LINQ查询



我正在尝试提出以下查询:

给我所有与某个帐户有直接联系的联系人。

到目前为止我写的是:

            var account = (Account)Context.Session["account"];
            var contacts = from ct in xrm.ContactSet
                              join cn in xrm.ConnectionSet
                              on ct.Id equals cn.Record2Id.Id
                              //&& cn.Record1Id.Id equals account.Id - can't really stick that there as per LINQ syntax standard...
                              select ct;

这显然是行不通的,但我认为这是我正在努力做的。

有什么想法吗?

使用连接的另一端作为where子句

var contacts = from ct in xrm.ContactSet
               join cn in xrm.ConnectionSet on ct.Id equals cn.Record2Id.Id
               where cn.Record1Id.Id == account.Id
               select ct;

这实际上将获得任何连接的两边,其中Account和Contact以任何方式相关

最新更新