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


C# QueryExpression.AddLink方法代码示例

本文整理汇总了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();
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:40,代码来源:ExportLogic.cs

示例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();
        }
开发者ID:josephmcmac,项目名称:JosephM.Xrm.Autonumber,代码行数:19,代码来源:AutonumberService.cs

示例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;
        }
开发者ID:cgoconseils,项目名称:XrmFramework,代码行数:19,代码来源:DataAccessManager.cs

示例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;
        }
开发者ID:BISmb,项目名称:Projects,代码行数:22,代码来源:UserOpQuery.cs

示例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);
 }
开发者ID:josephmcmac,项目名称:JosephM.Xrm,代码行数:13,代码来源:XrmService.cs

示例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);
 }
开发者ID:josephmcmac,项目名称:JosephM.Xrm,代码行数:11,代码来源:XrmService.cs

示例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);
 }
开发者ID:josephmcmac,项目名称:JosephM.Xrm,代码行数:9,代码来源:XrmService.cs

示例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);
 }
开发者ID:josephmcmac,项目名称:JosephM.Xrm,代码行数:8,代码来源:XrmService.cs

示例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;
            });
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:40,代码来源:ControlViewModel.cs

示例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];
//.........这里部分代码省略.........
开发者ID:cgoconseils,项目名称:XrmFramework,代码行数:101,代码来源:DataAccessManager.cs

示例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();
            });
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:30,代码来源:ControlViewModel.cs

示例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();
            });
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:31,代码来源:ControlViewModel.cs

示例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;
            });
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:22,代码来源:ControlViewModel.cs

示例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();
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:16,代码来源:ExportLogic.cs

示例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;
        }
开发者ID:josephmcmac,项目名称:JosephM.Xrm.Autonumber,代码行数:47,代码来源:AutonumberService.cs


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