本文整理汇总了C#中QueryExpression.AddLink方法的典型用法代码示例。如果您正苦于以下问题:C# QueryExpression.AddLink方法的具体用法?C# QueryExpression.AddLink怎么用?C# QueryExpression.AddLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryExpression
的用法示例。
在下文中一共展示了QueryExpression.AddLink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RetrieveTeams
public List<Team> RetrieveTeams()
{
var query = new QueryExpression("team");
query.NoLock = true;
query.Distinct = true;
query.ColumnSet = new ColumnSet(true);
query.Criteria.AddCondition("isdefault", ConditionOperator.Equal, false);
query.Criteria.AddCondition("systemmanaged", ConditionOperator.Equal, false);
var bu = query.AddLink("businessunit", "businessunitid", "businessunitid", JoinOperator.Inner);
bu.EntityAlias = "businessunitid";
bu.Columns = new ColumnSet("parentbusinessunitid");
var admin = query.AddLink("systemuser", "administratorid", "systemuserid", JoinOperator.LeftOuter);
admin.EntityAlias = "administratorid";
admin.Columns = new ColumnSet("domainname");
var result = OrganizationService.RetrieveMultiple(query);
return result.Entities.Select(e =>
{
var roles = LoadSecurityRoles(e.Id);
return new Team
{
TeamId = e.Id,
Name = e["name"] as string,
Type = e.FormattedValues["teamtype"],
IsInRootBusinessUnit = GetIsUnderDefaultBusinessUnit(e),
BusinessUnit = GetNameFromEntityReference(e, "businessunitid"),
AdministratorDomainName = GetAdministrator(e),
AdministratorFullName = GetNameFromEntityReference(e, "administratorid"),
Currency = GetNameFromEntityReference(e, "transactioncurrencyid"),
Attributes = e.Attributes
.Where(a => !_attributesToSkip.Contains(a.Key))
.ToDictionary(a => a.Key, a => a.Value),
SecurityRoles = roles
};
}).OrderBy(e => e.Name).ToList();
}
示例2: GetAutonumbers
private IEnumerable<XrmAutonumber> GetAutonumbers(IEnumerable<ConditionExpression> conditions)
{
var query = new QueryExpression(Entities.jmcg_autonumber);
query.ColumnSet = new ColumnSet(true);
if (conditions != null)
{
foreach (var item in conditions)
query.Criteria.AddCondition(item);
}
var link = query.AddLink(Entities.jmcg_autonumber, Fields.jmcg_autonumber_.jmcg_parentautonumber,
Fields.jmcg_autonumber_.jmcg_autonumberid);
link.JoinOperator = JoinOperator.LeftOuter;
link.EntityAlias = ParentAlias;
link.Columns = new ColumnSet(true);
return XrmService.RetrieveAll(query)
.Select(e => new XrmAutonumber(e))
.ToArray();
}
示例3: DoConnect
object DoConnect(object arg)
{
SendStepChange("Connecting...");
_service = new OrganizationService("Xrm");
_service.Execute(new WhoAmIRequest());
SendStepChange("Connected!");
var solutionName = ConfigHelper.GetEntitiesSolutionUniqueName();
var query = new QueryExpression(Solution.EntityLogicalName);
query.ColumnSet.AllColumns = true;
query.Criteria.AddCondition("uniquename", ConditionOperator.Equal, solutionName);
var linkPublisher = query.AddLink(Publisher.EntityLogicalName, "publisherid", "publisherid");
linkPublisher.EntityAlias = "publisher";
linkPublisher.Columns.AddColumn("customizationprefix");
_solution = _service.RetrieveMultiple(query).Entities.Select(s => s.ToEntity<Solution>()).FirstOrDefault();
return _service;
}
示例4: TeamMasterLogicMethod
static public bool TeamMasterLogicMethod(IOrganizationService service, Guid User)
{
QueryExpression teamQuery = new QueryExpression("team");
ColumnSet teamColumnSet = new ColumnSet("name");
teamQuery.ColumnSet = teamColumnSet;
teamQuery.Criteria = new FilterExpression();
teamQuery.Criteria.FilterOperator = LogicalOperator.And;
// teamQuery.Criteria.AddCondition("name", ConditionOperator.Equal, "Sales");
teamQuery.AddLink("teammembership", "teamid", "teamid").AddLink("systemuser", "systemuserid", "systemuserid").LinkCriteria.AddCondition("systemuserid", ConditionOperator.Equal, User);
EntityCollection teamDetail = service.RetrieveMultiple(teamQuery);
foreach (Entity ent in teamDetail.Entities)
{
string query = generateFetchForTeamMaster(ent.Id.ToString());
if (retrievePermision(service, query))
return true;
}
return false;
}
示例5: GetLinkedRecord
public Entity GetLinkedRecord(string linkedRecordType, string linkThroughRecordType, string linkFromRecordType,
string linkThroughLookup, string linkFromLookup, Guid linkFromId, string[] fields)
{
var query = new QueryExpression(linkedRecordType);
query.ColumnSet = CreateColumnSet(fields);
var linkThrough = query.AddLink(linkThroughRecordType, XrmEntity.GetPrimaryKeyName(linkedRecordType),
linkThroughLookup);
var linkFrom = linkThrough.AddLink(linkFromRecordType,
XrmEntity.GetPrimaryKeyName(linkThroughRecordType), linkFromLookup);
linkFrom.LinkCriteria.AddCondition(new ConditionExpression(XrmEntity.GetPrimaryKeyName(linkFromRecordType),
ConditionOperator.Equal, linkFromId));
return RetrieveFirst(query);
}
示例6: GetAssociatedEntities
public IEnumerable<Entity> GetAssociatedEntities(string entity, string entityId, string intersectId1,
Guid intersectGuid,
string relationshipName, string relatedEntity, string relatedEntityId, string intersectId2)
{
var query = new QueryExpression(relatedEntity);
var link = query.AddLink(relationshipName, intersectId2, intersectId2);
var link2 = link.AddLink(entity, intersectId1, entityId);
link2.LinkCriteria.AddCondition(new ConditionExpression(entityId, ConditionOperator.Equal, intersectGuid));
query.ColumnSet = CreateColumnSet(null);
return RetrieveAll(query);
}
示例7: GetLinkedRecords
public IEnumerable<Entity> GetLinkedRecords(string entity, string entityId, Guid entityGuid, string linkedType,
string lookup)
{
var query = new QueryExpression(linkedType);
var link = query.AddLink(entity, lookup, entityId);
link.LinkCriteria.AddCondition(new ConditionExpression(entityId, ConditionOperator.Equal, entityGuid));
query.ColumnSet = CreateColumnSet(null);
return RetrieveAll(query);
}
示例8: GetUserRoles
public IEnumerable<Entity> GetUserRoles(Guid userId, string[] columns)
{
var query = new QueryExpression("role");
query.ColumnSet = new ColumnSet(columns);
var userRole = query.AddLink("systemuserroles", "roleid", "roleid");
userRole.LinkCriteria.AddCondition("systemuserid", ConditionOperator.Equal, userId);
return RetrieveAll(query);
}
示例9: LoadAssemblies
private Task<List<Assembly>> LoadAssemblies()
{
return Task.Run(() =>
{
var query = new QueryExpression("pluginassembly");
query.Distinct = true;
query.NoLock = true;
query.ColumnSet = new ColumnSet("name", "pluginassemblyid");
query.AddOrder("name", OrderType.Ascending);
var type = query.AddLink("plugintype", "pluginassemblyid", "pluginassemblyid", JoinOperator.Inner);
type.LinkCriteria.AddCondition("typename", ConditionOperator.NotLike, "Microsoft.Crm.%");
type.LinkCriteria.AddCondition("typename", ConditionOperator.NotLike, "ActivityFeeds.%");
var result = _service.RetrieveMultiple(query);
var assemblies = result.Entities.Select(e => new Assembly
{
AssemblyId = e.Id,
Export = false,
Name = e["name"] as string,
RegisteredStepCount = 0
}).ToList();
foreach (var assembly in assemblies)
{
query = new QueryExpression("sdkmessageprocessingstep");
query.Distinct = true;
query.NoLock = true;
query.ColumnSet = new ColumnSet("sdkmessageprocessingstepid");
type = query.AddLink("plugintype", "plugintypeid", "plugintypeid");
type.LinkCriteria.AddCondition("pluginassemblyid", ConditionOperator.Equal, assembly.AssemblyId);
result = _service.RetrieveMultiple(query);
assembly.RegisteredStepCount = result.Entities.Count;
}
return assemblies;
});
}
示例10: DoRetrieveEntities
object DoRetrieveEntities(object arg)
{
SendStepChange("Retrieving entities...");
var entities = new List<EntityDefinition>();
var queryComponents = new QueryExpression(SolutionComponent.EntityLogicalName);
queryComponents.ColumnSet.AllColumns = true;
queryComponents.Criteria.AddCondition("componenttype", ConditionOperator.Equal, (int)componenttype.Entity);
var linkSolution = queryComponents.AddLink(Solution.EntityLogicalName, "solutionid", "solutionid");
linkSolution.EntityAlias = "solution";
linkSolution.Columns.AddColumn("uniquename");
var linkPublisher = linkSolution.AddLink(Publisher.EntityLogicalName, "publisherid", "publisherid");
linkPublisher.EntityAlias = "publisher";
linkPublisher.Columns.AddColumn("customizationprefix");
queryComponents.Criteria.AddCondition("solutionid", ConditionOperator.Equal, _solution.Id);
var components = _service.RetrieveMultiple(queryComponents).Entities;
var max = components.Count;
var current = 1;
foreach (SolutionComponent component in components)
{
var entity = _service.RetrieveEntity(new RetrieveEntityRequest { MetadataId = component.ObjectId.Value, EntityFilters = EntityFilters.Entity | EntityFilters.Attributes | EntityFilters.Relationships }).EntityMetadata;
var solutionName = component.GetAttributeValue<AliasedValue>("solution.uniquename").Value as string;
Prefix = component.GetAttributeValue<AliasedValue>("publisher.customizationprefix").Value as string;
var entityDefinition = new EntityDefinition
{
LogicalName = entity.LogicalName,
Name = RemovePrefix(entity.SchemaName).FormatText() + "Definition",
IsActivity = entity.IsActivity.Value,
IsLoaded = true
};
ClassDefinition keyDefinition = null;
if (entity.Keys != null && entity.Keys.Any())
{
keyDefinition = new ClassDefinition
{
LogicalName = "AlternateKeyNames",
Name = "AlternateKeyNames"
};
entityDefinition.AdditionalClassesCollection.Add(keyDefinition);
foreach (var key in entity.Keys)
{
keyDefinition.Attributes.Add(new AttributeDefinition { LogicalName = key.LogicalName, Name = key.DisplayName.UserLocalizedLabel.Label.FormatText(), Value = key.LogicalName });
}
}
if (entity.OneToManyRelationships.Any())
{
var classDefinition = new ClassDefinition
{
LogicalName = "OneToManyRelationships",
Name = "OneToManyRelationships"
};
entityDefinition.AdditionalClassesCollection.Add(classDefinition);
foreach (var relationship in entity.OneToManyRelationships)
{
classDefinition.Attributes.Add(new AttributeDefinition { LogicalName = relationship.SchemaName, Name = relationship.SchemaName, Value = relationship.SchemaName });
}
}
if (entity.ManyToManyRelationships.Any())
{
var classDefinition = new ClassDefinition
{
LogicalName = "ManyToManyRelationships",
Name = "ManyToManyRelationships"
};
entityDefinition.AdditionalClassesCollection.Add(classDefinition);
foreach (var relationship in entity.ManyToManyRelationships)
{
classDefinition.Attributes.Add(new AttributeDefinition { LogicalName = relationship.SchemaName, Name = relationship.SchemaName, Value = relationship.SchemaName });
}
}
var lookupFields = new Dictionary<string, List<OneToManyRelationshipMetadata>>();
if (entity.ManyToOneRelationships.Any())
{
ClassDefinition classDefinition = new ClassDefinition
{
LogicalName = "ManyToOneRelationships",
Name = "ManyToOneRelationships"
};
entityDefinition.AdditionalClassesCollection.Add(classDefinition);
foreach (var relationship in entity.ManyToOneRelationships)
{
classDefinition.Attributes.Add(new AttributeDefinition { LogicalName = relationship.SchemaName, Name = relationship.SchemaName, Value = relationship.SchemaName });
List<OneToManyRelationshipMetadata> list;
if (lookupFields.ContainsKey(relationship.ReferencingAttribute))
{
list = lookupFields[relationship.ReferencingAttribute];
//.........这里部分代码省略.........
示例11: LoadRoles
private Task<List<Role>> LoadRoles()
{
return Task.Run(() =>
{
var query = new QueryExpression("role");
query.NoLock = true;
query.ColumnSet = new ColumnSet("name", "roleid");
query.AddOrder("name", OrderType.Ascending);
var bu = query.AddLink("businessunit", "businessunitid", "businessunitid");
bu.LinkCriteria.AddCondition("parentbusinessunitid", ConditionOperator.Null);
var result = _service.RetrieveMultiple(query);
var roles = result.Entities.Select(e => new Role
{
RoleId = e.Id,
Name = e["name"] as string
});
roles = roles.Concat(new Role[] {
new Role
{
RoleId = Guid.Empty,
Name = " -- Users without an assigned role -- "
}
});
return roles.OrderBy(r => r.Name).ToList();
});
}
示例12: LoadPrivileges
private Task<List<Privilege>> LoadPrivileges(Guid roleId)
{
return Task.Run(() =>
{
var query = new QueryExpression("privilege");
query.NoLock = true;
query.ColumnSet = new ColumnSet("name", "accessright");
query.AddOrder("name", OrderType.Ascending);
var typecode = query.AddLink("privilegeobjecttypecodes", "privilegeid", "privilegeid", JoinOperator.LeftOuter);
typecode.EntityAlias = "privilegeobjecttypecode";
typecode.Columns = new ColumnSet("objecttypecode");
var intersect = query.AddLink("roleprivileges", "privilegeid", "privilegeid");
intersect.EntityAlias = "roleprivilege";
intersect.Columns = new ColumnSet("privilegedepthmask");
var role = intersect.AddLink("role", "roleid", "roleid");
role.LinkCriteria.AddCondition("roleid", ConditionOperator.Equal, roleId);
var result = _service.RetrieveMultiple(query);
return result.Entities.Select(e => new Privilege
{
PrivilegeId = e.Id,
Name = e["name"] as string,
AccessRight = GetAccessRight(e),
LogicalName = GetEntityName(e),
Depth = GetDepth(e)
}).ToList();
});
}
示例13: LoadRoles
private Task<IEnumerable<Role>> LoadRoles()
{
return Task.Run(() =>
{
var query = new QueryExpression("role");
query.NoLock = true;
query.ColumnSet = new ColumnSet("name", "roleid");
query.AddOrder("name", OrderType.Ascending);
var bu = query.AddLink("businessunit", "businessunitid", "businessunitid");
bu.LinkCriteria.AddCondition("parentbusinessunitid", ConditionOperator.Null);
var result = _service.RetrieveMultiple(query);
var roles = result.Entities.Select(e => new Role
{
RoleId = e.Id,
Name = e["name"] as string
});
return roles;
});
}
示例14: LoadSecurityRoles
private List<string> LoadSecurityRoles(Guid teamId)
{
var query = new QueryExpression("role");
query.NoLock = true;
query.Distinct = true;
query.ColumnSet = new ColumnSet("name");
var teamroles = query.AddLink("teamroles", "roleid", "roleid", JoinOperator.Inner);
teamroles.LinkCriteria.AddCondition("teamid", ConditionOperator.Equal, teamId);
var result = OrganizationService.RetrieveMultiple(query);
return result.Entities
.Select(e => e["name"] as string)
.ToList();
}
示例15: GetParentEntity
/// <summary>
/// Return the entity record which is configured as the logical parent of this records autonumber
/// </summary>
public Entity GetParentEntity(Entity entity, XrmAutonumber autonumber, IEnumerable<string> fields)
{
//Need to split the links to the parent and create a query which returns the parent record via the links
if (!entity.Contains(autonumber.FirstLinkLookup))
return null;
//Create a query which traverses through the keys and entities we defined in our autonumber links
var query = new QueryExpression();
query.ColumnSet = XrmService.CreateColumnSet(fields);
LinkEntity carry = null;
//for each foreign key entity pairing work from last to first
for (var i = autonumber.LinksToParent.LinkToParents.Count(); i > 0; i--)
{
var thisLink = autonumber.LinksToParent.LinkToParents.ElementAt(i - 1);
//if this is the last item we need to create it as the type of entity we are returning
if (i == autonumber.LinksToParent.LinkToParents.Count())
query.EntityName = thisLink.LinkTarget;
//otherwise if this is not the last item we need to add a link from the previous type to this type
else
{
var previousPair = autonumber.LinksToParent.LinkToParents.ElementAt(i);
if (carry == null)
carry = query.AddLink(thisLink.LinkTarget, previousPair.LinkFieldTarget, previousPair.LinkFieldSource);
else
carry = carry.AddLink(thisLink.LinkTarget, previousPair.LinkFieldTarget, previousPair.LinkFieldSource);
}
//if this is the first item we need to add a filter on the first id with the value in the lookup from the record we are creating the autonumber for
if (i == 1)
{
var thisLookupId = entity.GetLookupGuid(thisLink.LinkFieldSource);
if (!thisLookupId.HasValue)
return null;
if (autonumber.LinksToParent.LinkToParents.Count() != 1)
carry.LinkCriteria.AddCondition(carry.LinkToEntityName + "id", ConditionOperator.Equal, thisLookupId.Value);
else
query.Criteria.AddCondition(query.EntityName + "id", ConditionOperator.Equal, thisLookupId.Value);
}
}
//Run the query and if a result return it
var parent = XrmService.RetrieveMultiple(query);
if (parent.Entities.Count > 0)
return parent.Entities[0];
return null;
}