本文整理汇总了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 ();
}
示例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();
}
示例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 ();
}