Question

I'm trying to come up with the following query:

Get me all the contacts who are simply connected to a certain account.

Here's what I have so far:

            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;

This obviously does not work, but I think it's obvious what I am trying to do.

Any ideas ?

Was it helpful?

Solution

Just use the other side of the connection as the where clause

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;

This will actually get both sides of any connection, where the Account and Contact are related any which way round

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top