本文整理汇总了C#中FakeXrmEasy.XrmFakedContext.AddRelationship方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.AddRelationship方法的具体用法?C# XrmFakedContext.AddRelationship怎么用?C# XrmFakedContext.AddRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FakeXrmEasy.XrmFakedContext
的用法示例。
在下文中一共展示了XrmFakedContext.AddRelationship方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_related_entities_and_relationship_are_used_child_entities_are_created
public void When_related_entities_and_relationship_are_used_child_entities_are_created()
{
var ctx = new XrmFakedContext();
var service = ctx.GetFakedOrganizationService();
ctx.AddRelationship("order_details",
new XrmFakedRelationship()
{
Entity1LogicalName = SalesOrder.EntityLogicalName, //Referenced
Entity1Attribute = "salesorderid", //Pk
Entity2LogicalName = SalesOrderDetail.EntityLogicalName,
Entity2Attribute = "salesorderid", //Lookup attribute
RelationshipType = XrmFakedRelationship.enmFakeRelationshipType.OneToMany
});
var order = new SalesOrder();
var orderItems = new EntityCollection(new List<Entity>()
{
new SalesOrderDetail(),
new SalesOrderDetail()
});
// Add related order items so it can be created in one request
order.RelatedEntities.Add(new Relationship
{
PrimaryEntityRole = EntityRole.Referenced,
SchemaName = "order_details"
}, orderItems);
var request = new CreateRequest
{
Target = order
};
var id = (service.Execute(request) as CreateResponse).id;
var createdOrderDetails = ctx.CreateQuery<SalesOrderDetail>().ToList();
Assert.Equal(createdOrderDetails.Count, 2);
Assert.Equal(createdOrderDetails[0].SalesOrderId.Id, id);
Assert.Equal(createdOrderDetails[1].SalesOrderId.Id, id);
}