本文整理汇总了C#中XrmServiceContext.AddRelatedObject方法的典型用法代码示例。如果您正苦于以下问题:C# XrmServiceContext.AddRelatedObject方法的具体用法?C# XrmServiceContext.AddRelatedObject怎么用?C# XrmServiceContext.AddRelatedObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XrmServiceContext
的用法示例。
在下文中一共展示了XrmServiceContext.AddRelatedObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_calling_context_add_addrelated_and_save_changes_entities_are_added_to_the_faked_context
public void When_calling_context_add_addrelated_and_save_changes_entities_are_added_to_the_faked_context()
{
var context = new XrmFakedContext();
var relationship = new XrmFakedRelationship()
{
IntersectEntity = "accountleads",
Entity1Attribute = "accountid",
Entity2Attribute = "leadid",
Entity1LogicalName = "account",
Entity2LogicalName = "lead"
};
context.AddRelationship("accountleads", relationship);
var service = context.GetFakedOrganizationService();
using (var ctx = new XrmServiceContext(service))
{
var account = new Account() { Name = "Test account" };
ctx.AddObject(account);
var contact = new Lead() { FirstName = "Jane", LastName = "Doe" };
ctx.AddRelatedObject(account, new Relationship("accountleads"), contact);
var result = ctx.SaveChanges();
var resultaccount = ctx.CreateQuery<Account>()
.ToList()
.FirstOrDefault();
Assert.NotNull(resultaccount);
Assert.Equal("Test account", resultaccount.Name);
var reaultlead = ctx.CreateQuery<Lead>()
.ToList()
.FirstOrDefault();
Assert.NotNull(reaultlead);
Assert.Equal("Jane", reaultlead.FirstName);
Assert.Equal("Doe", reaultlead.LastName);
var relationshipRecords = ctx.CreateQuery("accountleads")
.ToList();
Assert.NotEmpty(relationshipRecords);
}
}