当前位置: 首页>>代码示例>>C#>>正文


C# XrmFakedContext.AddRelationship方法代码示例

本文整理汇总了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);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:42,代码来源:FakeContextTestCreate.cs


注:本文中的FakeXrmEasy.XrmFakedContext.AddRelationship方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。