Ejemplo n.º 1
0
        public static IEdmModel BuildEdmModel(ODataModelBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            EdmModel           model     = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName);

            // add types and sets, building an index on the way.
            IEnumerable <IEdmTypeConfiguration> configTypes = builder.StructuralTypes.Concat <IEdmTypeConfiguration>(builder.EnumTypes);
            EdmTypeMap edmMap = EdmTypeBuilder.GetTypesAndProperties(configTypes);
            Dictionary <Type, IEdmType> edmTypeMap = model.AddTypes(edmMap);

            // Add EntitySets and build the mapping between the EdmEntitySet and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] entitySets = container.AddEntitySetAndAnnotations(builder, edmTypeMap);

            // Add Singletons and build the mapping between the EdmSingleton and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] singletons = container.AddSingletonAndAnnotations(builder, edmTypeMap);

            // Merge EntitySets and Singletons together
            IEnumerable <NavigationSourceAndAnnotations> navigationSources = entitySets.Concat(singletons);

            // Build the navigation source map
            IDictionary <string, EdmNavigationSource> navigationSourceMap = model.GetNavigationSourceMap(edmMap, navigationSources);

            // Add the core vocabulary annotations
            model.AddCoreVocabularyAnnotations(navigationSources, edmMap);

            // TODO: support etags on contained nav props
            // Support for this in 5.x adds annotations to navigation properties. Ideally would add annotations to entity set/singleton for
            // containing type(s) with nav paths to the contained nav property.
            // model.AddNavPropAnnotations(builder, edmMap);  // implemented in EdmModelHelperMethods.cs of 5.x branch

            // Add the capabilities vocabulary annotations
            model.AddCapabilitiesVocabularyAnnotations(navigationSources, edmMap);

            // add operations
            model.AddOperations(builder.Operations, container, edmTypeMap, navigationSourceMap);

            // finish up
            model.AddElement(container);

            // build the map from IEdmEntityType to IEdmFunctionImport
            model.SetAnnotationValue <BindableOperationFinder>(model, new BindableOperationFinder(model));

            return(model);
        }
Ejemplo n.º 2
0
        public static IEdmModel BuildEdmModel(ODataModelBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            EdmModel           model     = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName);

            // add types and sets, building an index on the way.
            IEnumerable <IEdmTypeConfiguration> configTypes = builder.StructuralTypes.Concat <IEdmTypeConfiguration>(builder.EnumTypes);
            EdmTypeMap edmMap = EdmTypeBuilder.GetTypesAndProperties(configTypes);
            Dictionary <Type, IEdmType> edmTypeMap = model.AddTypes(edmMap);

            // Add EntitySets and build the mapping between the EdmEntitySet and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] entitySets = container.AddEntitySetAndAnnotations(builder, edmTypeMap);

            // Add Singletons and build the mapping between the EdmSingleton and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] singletons = container.AddSingletonAndAnnotations(builder, edmTypeMap);

            // Merge EntitySets and Singletons together
            IEnumerable <NavigationSourceAndAnnotations> navigationSources = entitySets.Concat(singletons);

            // Build the navigation source map
            IDictionary <string, EdmNavigationSource> navigationSourceMap = model.GetNavigationSourceMap(builder, edmTypeMap, navigationSources);

            // Add the core vocabulary annotations
            model.AddCoreVocabularyAnnotations(navigationSources, edmMap);

            // Add the nav property annotations
            model.AddNavPropAnnotations(builder, edmMap);

            // Add the capabilities vocabulary annotations
            model.AddCapabilitiesVocabularyAnnotations(entitySets, edmMap);

            // add procedures
            model.AddProcedures(builder.Procedures, container, edmTypeMap, navigationSourceMap);

            // finish up
            model.AddElement(container);

            // build the map from IEdmEntityType to IEdmFunctionImport
            model.SetAnnotationValue <BindableProcedureFinder>(model, new BindableProcedureFinder(model));

            return(model);
        }