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


C# XrmFakedContext.AttributeExistsInMetadata方法代码示例

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


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

示例1: ProjectAttributes

        public static Entity ProjectAttributes(this Entity e, QueryExpression qe, XrmFakedContext context)
        {
            if (qe.ColumnSet == null) return e;

            if (qe.ColumnSet.AllColumns)
            {
                return e; //return all the original attributes
            }
            else
            {
                //Return selected list of attributes in a projected entity
                Entity projected = null;

                //However, if we are using proxy types, we must create a instance of the appropiate class
                if (context.ProxyTypesAssembly != null)
                {
                    var subClassType = context.FindReflectedType(e.LogicalName);
                    if (subClassType != null)
                    {
                        var instance = Activator.CreateInstance(subClassType);
                        projected = (Entity)instance;
                        projected.Id = e.Id;
                    }
                    else 
                        projected = new Entity(e.LogicalName) { Id = e.Id }; //fallback to generic type if type not found
                }
                else 
                    projected = new Entity(e.LogicalName) { Id = e.Id };

                foreach (var attKey in qe.ColumnSet.Columns)
                {
                    //Check if attribute really exists in metadata
                    if (!context.AttributeExistsInMetadata(e.LogicalName, attKey))
                    {
                        OrganizationServiceFaultQueryBuilderNoAttributeException.Throw(attKey);
                    }

                    if (e.Attributes.ContainsKey(attKey))
                        projected[attKey] = e[attKey];
                    else
                    {
                        projected[attKey] = null;
                    }
                }

                //Plus attributes from joins
                foreach(var le in qe.LinkEntities)
                {
                    ProjectAttributes(e, projected, le, context);
                }
                //foreach (var attKey in e.Attributes.Keys)
                //{
                //    if(e[attKey] is AliasedValue && !projected.Attributes.ContainsKey(attKey))
                //        projected[attKey] = e[attKey];
                //}
                return projected;
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:58,代码来源:EntityExtensions.cs

示例2: JoinAttributes

        public static Entity JoinAttributes(this Entity e, IEnumerable<Entity> otherEntities, ColumnSet columnSet, string alias, XrmFakedContext context)
        {
            foreach (var otherEntity in otherEntities) {
                var otherClonedEntity = otherEntity.Clone(); //To avoid joining entities from/to the same entities, which would cause collection modified exceptions

                if (columnSet.AllColumns)
                {
                    foreach (var attKey in otherClonedEntity.Attributes.Keys)
                    {
                        e[alias + "." + attKey] = new AliasedValue(alias, attKey, otherClonedEntity[attKey]);
                    }
                }
                else
                {
                    //Return selected list of attributes
                    foreach (var attKey in columnSet.Columns)
                    {
                        if (!context.AttributeExistsInMetadata(otherEntity.LogicalName, attKey))
                        {
                            OrganizationServiceFaultQueryBuilderNoAttributeException.Throw(attKey);
                        }

                        if (otherClonedEntity.Attributes.ContainsKey(attKey))
                        {
                            e[alias + "." + attKey] = new AliasedValue(alias, attKey, otherClonedEntity[attKey]);
                        }
                        else {
                            e[alias + "." + attKey] = new AliasedValue(alias, attKey, null);
                        }
                    }
                }
            }
            return e;
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:34,代码来源:EntityExtensions.cs


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