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


C# XrmFakedContext.GetRelationship方法代码示例

本文整理汇总了C#中XrmFakedContext.GetRelationship方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.GetRelationship方法的具体用法?C# XrmFakedContext.GetRelationship怎么用?C# XrmFakedContext.GetRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XrmFakedContext的用法示例。


在下文中一共展示了XrmFakedContext.GetRelationship方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var associateRequest = request as AssociateRequest;
            var service = ctx.GetFakedOrganizationService();

            if (associateRequest == null)
            {
                throw new Exception("Only associate request can be processed!");
            }

            var associateRelationship = associateRequest.Relationship;
            var relationShipName = associateRelationship.SchemaName;
            var fakeRelationShip = ctx.GetRelationship(relationShipName);

            if (fakeRelationShip == null)
            {
                throw new Exception(string.Format("Relationship {0} does not exist in the metadata cache", relationShipName));
            }

            if (associateRequest.Target == null)
            {
                throw new Exception("Association without target is invalid!");
            }

            foreach (var relatedEntityReference in associateRequest.RelatedEntities)
            {
                if (fakeRelationShip.RelationshipType == XrmFakedRelationship.enmFakeRelationshipType.ManyToMany)
                {
                    var association = new Entity(fakeRelationShip.IntersectEntity)
                    {
                        Attributes = new AttributeCollection
                        {
                            { fakeRelationShip.Entity1Attribute, associateRequest.Target.Id },
                            { fakeRelationShip.Entity2Attribute, relatedEntityReference.Id }
                        }
                    };

                    service.Create(association);
                }
                else
                {
                    //One to many
                    //Get entity to update
                    var entityToUpdate = new Entity(relatedEntityReference.LogicalName)
                    {
                        Id = relatedEntityReference.Id
                    };

                    entityToUpdate[fakeRelationShip.Entity2Attribute] = associateRequest.Target;
                    service.Update(entityToUpdate);
                }

            }

            return new AssociateResponse ();
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:56,代码来源:AssociateRequestExecutor.cs

示例2: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var disassociateRequest = request as DisassociateRequest;
            var service = ctx.GetFakedOrganizationService();

            if (disassociateRequest == null)
            {
                throw new Exception("Only disassociate request can be processed!");
            }

            var relationShipName = disassociateRequest.Relationship.SchemaName;
            var relationShip = ctx.GetRelationship(relationShipName);

            if (relationShip == null)
            {
                throw new Exception(string.Format("Relationship {0} does not exist in the metadata cache", relationShipName));
            }

            if (disassociateRequest.Target == null)
            {
                throw new Exception("Disassociation without target is invalid!");
            }

            foreach (var relatedEntity in disassociateRequest.RelatedEntities)
            {
                var query = new QueryExpression(relationShip.IntersectEntity)
                {
                    ColumnSet = new ColumnSet(true),
                    Criteria = new FilterExpression(LogicalOperator.And)
                };

                query.Criteria.AddCondition(new ConditionExpression(relationShip.Entity1Attribute,
                    ConditionOperator.Equal, disassociateRequest.Target.Id));
                query.Criteria.AddCondition(new ConditionExpression(relationShip.Entity2Attribute,
                    ConditionOperator.Equal, relatedEntity.Id));

                var results = service.RetrieveMultiple(query);

                if (results.Entities.Count == 1)
                {
                    service.Delete(relationShip.IntersectEntity, results.Entities.First().Id);
                }
            }

            return new DisassociateResponse();
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:46,代码来源:DisassociateRequestExecutor.cs

示例3: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var associateRequest = request as AssociateRequest;
            var service = ctx.GetFakedOrganizationService();

            if (associateRequest == null)
            {
                throw new Exception("Only associate request can be processed!");
            }

            var relationShipName = associateRequest.Relationship.SchemaName;
            var relationShip = ctx.GetRelationship(relationShipName);

            if (relationShip == null)
            {
                throw new Exception(string.Format("Relationship {0} does not exist in the metadata cache", relationShipName));
            }

            if (associateRequest.Target == null)
            {
                throw new Exception("Association without target is invalid!");
            }

            foreach (var relatedEntity in associateRequest.RelatedEntities)
            {
                var association = new Entity(relationShip.IntersectEntity)
                {
                    Attributes = new AttributeCollection
                        {
                            { relationShip.Entity1Attribute, associateRequest.Target.Id },
                            { relationShip.Entity2Attribute, relatedEntity.Id }
                        }
                };

                service.Create(association);


            }

            return new AssociateResponse ();
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:41,代码来源:AssociateRequestExecutor.cs


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