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


C# MetadataWorkspace.TryGetEdmSpaceType方法代码示例

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


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

示例1: GetEdmType

        /// <summary>
        /// Retrieves the <see cref="StructuralType"/> corresponding to the given CLR type (where the
        /// type is an entity or complex type).
        /// </summary>
        /// <remarks>
        /// If no mapping exists for <paramref name="clrType"/>, but one does exist for one of its base 
        /// types, we will return the mapping for the base type.
        /// </remarks>
        /// <param name="workspace">The <see cref="MetadataWorkspace"/></param>
        /// <param name="clrType">The CLR type</param>
        /// <returns>The <see cref="StructuralType"/> corresponding to that CLR type, or <c>null</c> if the Type
        /// is not mapped.</returns>
        public static StructuralType GetEdmType(MetadataWorkspace workspace, Type clrType)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException("workspace");
            }
            if (clrType == null)
            {
                throw new ArgumentNullException("clrType");
            }

            if (clrType.IsPrimitive || clrType == typeof(object))
            {
                // want to avoid loading searching system assemblies for
                // types we know aren't entity or complex types
                return null;
            }

            // We first locate the EdmType in "OSpace", which matches the name and namespace of the CLR type
            EdmType edmType = null;
            do
            {
                if (!workspace.TryGetType(clrType.Name, clrType.Namespace, DataSpace.OSpace, out edmType))
                {
                    // If EF could not find this type, it could be because it is not loaded into
                    // its current workspace.  In this case, we explicitly load the assembly containing 
                    // the CLR type and try again.
                    workspace.LoadFromAssembly(clrType.Assembly);
                    workspace.TryGetType(clrType.Name, clrType.Namespace, DataSpace.OSpace, out edmType);
                }
            }
            while (edmType == null && (clrType = clrType.BaseType) != typeof(object) && clrType != null);

            // Next we locate the StructuralType from the EdmType.
            // This 2-step process is necessary when the types CLR namespace does not match Edm namespace.
            // Look at the EdmEntityTypeAttribute on the generated entity classes to see this Edm namespace.
            StructuralType structuralType = null;
            if (edmType != null &&
                (edmType.BuiltInTypeKind == BuiltInTypeKind.EntityType || edmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType))
            {
                workspace.TryGetEdmSpaceType((StructuralType)edmType, out structuralType);
            }

            return structuralType;
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:57,代码来源:ObjectContextUtilities.cs

示例2: GetCSpacetype

        public static EntityType GetCSpacetype(Type currentType, MetadataWorkspace mdw)
        {
            mdw.LoadFromAssembly(currentType.Assembly);

            EntityType ospaceEntityType = null;
            StructuralType cspaceEntityType = null;
            if (mdw.TryGetItem<EntityType>(
                currentType.FullName, DataSpace.OSpace, out ospaceEntityType))
            {
                if (mdw.TryGetEdmSpaceType(ospaceEntityType,
                    out cspaceEntityType))
                    return cspaceEntityType as EntityType;
            }

            return null;
        }
开发者ID:BostonSymphOrch,项目名称:HENRY-archives,代码行数:16,代码来源:BusinessObjectHelper.cs


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