//Collect the names of the entitysetbases and the generated views from
            //the generated type into a string so that we can produce a hash over it.
            private void SerializedAddGeneratedViews(MetadataWorkspace workspace, EntityViewContainer viewContainer, Dictionary <EntitySetBase, GeneratedView> extentMappingViews)
            {
                foreach (KeyValuePair <string, string> extentView in viewContainer.ExtentViews)
                {
                    EntityContainer entityContainer = null;
                    EntitySetBase   extent          = null;


                    string extentFullName  = extentView.Key;
                    int    extentNameIndex = extentFullName.LastIndexOf('.');

                    if (extentNameIndex != -1)
                    {
                        string entityContainerName = extentFullName.Substring(0, extentNameIndex);
                        string extentName          = extentFullName.Substring(extentFullName.LastIndexOf('.') + 1);

                        if (!workspace.TryGetItem <EntityContainer>(entityContainerName, DataSpace.CSpace, out entityContainer))
                        {
                            workspace.TryGetItem <EntityContainer>(entityContainerName, DataSpace.SSpace, out entityContainer);
                        }

                        if (entityContainer != null)
                        {
                            entityContainer.BaseEntitySets.TryGetValue(extentName, false, out extent);
                        }
                    }

                    if (extent == null)
                    {
                        throw new MappingException(System.Data.Entity.Strings.Generated_Views_Invalid_Extent(extentFullName));
                    }

                    //Create a Generated view and cache it
                    GeneratedView generatedView;
                    //Add the view to the local dictionary
                    if (!extentMappingViews.TryGetValue(extent, out generatedView))
                    {
                        generatedView = GeneratedView.CreateGeneratedView(
                            extent,
                            null,             // edmType
                            null,             // commandTree
                            extentView.Value, // eSQL
                            m_storageMappingItemCollection,
                            new ConfigViewGenerator());
                        extentMappingViews.Add(extent, generatedView);
                    }
                }
            }
Esempio n. 2
0
        private static StructuralType GetEdmType(MetadataWorkspace workspace)
        {
            StructuralType objectSpaceType;

            workspace.LoadFromAssembly(typeof(T).Assembly);
            if (!workspace.TryGetItem <StructuralType>(typeof(T).FullName, DataSpace.OSpace, out objectSpaceType))
            {
                //throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Messages.UnableToFindMetadataForType, typeof(T)));
            }
            StructuralType edmSpaceType = workspace.GetEdmSpaceType(objectSpaceType);

            return(edmSpaceType);
        }
        // <summary>
        // Look up a type in the target data space based upon the fullName
        // </summary>
        // <param name="fullName"> fullName </param>
        // <param name="ignoreCase"> true for case-insensitive lookup </param>
        // <returns> a list of types that have the specified full name but may differ by strong name </returns>
        internal override bool TryGetTypeByName(string fullName, bool ignoreCase, out TypeUsage usage)
        {
            Check.NotEmpty(fullName, "fullName");

            EdmType edmType = null;

            if (MetadataWorkspace.TryGetItem(fullName, ignoreCase, TargetDataspace, out edmType))
            {
                usage = TypeUsage.Create(edmType);
                usage = Helper.GetModelTypeUsage(usage);
                return(true);
            }

            return(_modelPerspective.TryGetTypeByName(fullName, ignoreCase, out usage));
        }
Esempio n. 4
0
        /// <summary>
        ///     Look up a type in the target data space based upon the fullName
        /// </summary>
        /// <param name="fullName"> fullName </param>
        /// <param name="ignoreCase"> true for case-insensitive lookup </param>
        /// <param name="typeUsage"> The type usage object to return </param>
        /// <returns> True if the retrieval succeeded </returns>
        internal override bool TryGetTypeByName(string fullName, bool ignoreCase, out TypeUsage typeUsage)
        {
            Check.NotEmpty(fullName, "fullName");
            typeUsage = null;
            EdmType edmType = null;

            if (MetadataWorkspace.TryGetItem(fullName, ignoreCase, TargetDataspace, out edmType))
            {
                if (Helper.IsPrimitiveType(edmType))
                {
                    typeUsage = MetadataWorkspace.GetCanonicalModelTypeUsage(((PrimitiveType)edmType).PrimitiveTypeKind);
                }
                else
                {
                    typeUsage = TypeUsage.Create(edmType);
                }
            }
            return(typeUsage != null);
        }
        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);
        }
            //Collect the names of the entitysetbases and the generated views from
            //the generated type into a string so that we can produce a hash over it.
            private void SerializedAddGeneratedViews(
                MetadataWorkspace workspace, EntityViewContainer viewContainer, Dictionary<EntitySetBase, GeneratedView> extentMappingViews)
            {
                foreach (var extentView in viewContainer.ExtentViews)
                {
                    EntityContainer entityContainer = null;
                    EntitySetBase extent = null;

                    var extentFullName = extentView.Key;
                    var extentNameIndex = extentFullName.LastIndexOf('.');

                    if (extentNameIndex != -1)
                    {
                        var entityContainerName = extentFullName.Substring(0, extentNameIndex);
                        var extentName = extentFullName.Substring(extentFullName.LastIndexOf('.') + 1);

                        if (!workspace.TryGetItem(entityContainerName, DataSpace.CSpace, out entityContainer))
                        {
                            workspace.TryGetItem(entityContainerName, DataSpace.SSpace, out entityContainer);
                        }

                        if (entityContainer != null)
                        {
                            entityContainer.BaseEntitySets.TryGetValue(extentName, false, out extent);
                        }
                    }

                    if (extent == null)
                    {
                        throw new MappingException(System.Data.Entity.Resources.Strings.Generated_Views_Invalid_Extent(extentFullName));
                    }

                    //Create a Generated view and cache it
                    GeneratedView generatedView;
                    //Add the view to the local dictionary
                    if (!extentMappingViews.TryGetValue(extent, out generatedView))
                    {
                        generatedView = GeneratedView.CreateGeneratedView(
                            extent,
                            null, // edmType
                            null, // commandTree
                            extentView.Value, // eSQL
                            m_storageMappingItemCollection,
                            new ConfigViewGenerator());
                        extentMappingViews.Add(extent, generatedView);
                    }
                }
            }
        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;
        }