本文整理汇总了C#中ServiceContext.LoadProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContext.LoadProperty方法的具体用法?C# ServiceContext.LoadProperty怎么用?C# ServiceContext.LoadProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContext
的用法示例。
在下文中一共展示了ServiceContext.LoadProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
//.........这里部分代码省略.........
Console.WriteLine();
//OUTPUT:
//Join account and contact
//List all records matching specified parameters
//Contact name: Wilcox or Andrews
//Account area code: 206 or 425
//==============================================
//Contact Name: Ben Andrews
//Account Phone: (206)555-5555
//Contact Name: Ben Andrews
//Account Phone: (425)555-5555
//Contact Name: Colin Wilcox
//Account Phone: (425)555-5555
//<End of Listing>
// Build a complex query with LINQ. This query includes multiple
// JOINs and a complex WHERE statement.
//<snippetUseLinqQuery4>
var complexQuery = from c in svcContext.ContactSet
join a in svcContext.AccountSet
on c.ContactId equals a.PrimaryContactId.Id
join l in svcContext.CreateQuery<Lead>()
on a.OriginatingLeadId.Id equals l.LeadId
where c.LastName == "Wilcox" || c.LastName == "Andrews"
where a.Address1_Telephone1.Contains("(206)")
|| a.Address1_Telephone1.Contains("(425)")
select new
{
Contact = new Contact
{
FirstName = c.FirstName,
LastName = c.LastName,
},
Account = new Account
{
Address1_Telephone1 = a.Address1_Telephone1
},
Lead = new Lead
{
LeadId = l.LeadId
}
};
Console.WriteLine("Join account, contact and lead");
Console.WriteLine("List all records matching specified parameters");
Console.WriteLine("Contact name: Wilcox or Andrews");
Console.WriteLine("Account area code: 206 or 425");
Console.WriteLine("==============================================");
foreach (var record in complexQuery)
{
Console.WriteLine("Lead ID: {0}",
record.Lead.LeadId);
Console.WriteLine("Contact Name: {0} {1}",
record.Contact.FirstName, record.Contact.LastName);
Console.WriteLine("Account Phone: {0}",
record.Account.Address1_Telephone1);
}
//</snippetUseLinqQuery4>
Console.WriteLine("<End of Listing>");
Console.WriteLine();
//OUTPUT:
//Join account, contact and lead
//List all records matching specified parameters
//Contact name: Wilcox or Andrews
//Account area code: 206 or 425
//==============================================
//Lead ID: 78d5df14-64a3-e011-aea3-00155dba3818
//Contact Name: Colin Wilcox
//Account Phone: (425)555-5555
//<End of Listing>
//Retrieve a related Task for a Contact
//Shows requirement that LoadProperty must be used to access the related record.
//<snippetUseLinqQuery5>
Contact benAndrews = svcContext.ContactSet.Where(c => c.FullName == "Ben Andrews").FirstOrDefault();
if (benAndrews != null)
{
//benAndrews.Contact_Tasks is null until LoadProperty is used.
svcContext.LoadProperty(benAndrews, "Contact_Tasks");
Task benAndrewsFirstTask = benAndrews.Contact_Tasks.FirstOrDefault();
if (benAndrewsFirstTask != null)
{
Console.WriteLine("Ben Andrews first task with Subject: '{0}' retrieved.", benAndrewsFirstTask.Subject);
}
}
//</snippetUseLinqQuery5>
DeleteRequiredRecords(promptForDelete);
}
}
// Catch any service fault exceptions that Microsoft Dynamics CRM throws.
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
{
// You can handle an exception here or pass it back to the calling method.
throw;
}
}