I've done a lot of hunting and can't find a single example of how to retrieve the Connection
information between an Account
and Contact
in Dynamics CRM 2011. Can someone point me in the right direction?
FYI, this is my usual method of retrieving data (it doesn't cover this issue and nothing I have tried has even come close to working)
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);
}
Thanks in advanced.
Edit: Updating answer to match requirements.
Details of connections are stored in the Connection entity set.
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!
}
Answered my own question. There is an example buried in MSDN that Google had ommitted from it's search results. MSDN example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.