private static EntityContainerMapping BuildEntityContainerMapping(SimpleMappingContext mappingContext)
        {
            var storeEntityContainer = mappingContext.StoreModel.Containers.Single();
            var entityContainerMapping =
                new EntityContainerMapping(
                    mappingContext[storeEntityContainer],
                    storeEntityContainer,
                    null,
                    false,
                    false);

            foreach (var entitySetMapping in BuildEntitySetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(entitySetMapping);
            }

            foreach (var associationSetMapping in BuildAssociationSetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(associationSetMapping);
            }

            foreach (var mappedStoredFunction in mappingContext.MappedStoreFunctions())
            {
                entityContainerMapping.AddFunctionImportMapping(
                    BuildComposableFunctionMapping(mappedStoredFunction, mappingContext));
            }

            return entityContainerMapping;
        }
Beispiel #2
0
        private static EntityContainerMapping BuildEntityContainerMapping(SimpleMappingContext mappingContext)
        {
            var storeEntityContainer   = mappingContext.StoreModel.Containers.Single();
            var entityContainerMapping =
                new EntityContainerMapping(
                    mappingContext[storeEntityContainer],
                    storeEntityContainer,
                    null,
                    false,
                    false);

            foreach (var entitySetMapping in BuildEntitySetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(entitySetMapping);
            }

            foreach (var associationSetMapping in BuildAssociationSetMappings(entityContainerMapping, mappingContext))
            {
                entityContainerMapping.AddSetMapping(associationSetMapping);
            }

            foreach (var mappedStoredFunction in mappingContext.MappedStoreFunctions())
            {
                entityContainerMapping.AddFunctionImportMapping(
                    BuildComposableFunctionMapping(mappedStoredFunction, mappingContext));
            }

            return(entityContainerMapping);
        }
Beispiel #3
0
        public static AssociationSetMapping AddAssociationSetMapping(
            this DbDatabaseMapping databaseMapping,
            AssociationSet associationSet,
            EntitySet entitySet)
        {
            EntityContainerMapping containerMapping = databaseMapping.EntityContainerMappings.Single <EntityContainerMapping>();
            AssociationSetMapping  setMapping       = new AssociationSetMapping(associationSet, entitySet, containerMapping).Initialize();

            containerMapping.AddSetMapping(setMapping);
            return(setMapping);
        }
        public void Can_get_association_set_mappings()
        {
            var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));

            Assert.Empty(entityContainerMapping.AssociationSetMappings);
            Assert.Empty(entityContainerMapping.RelationshipSetMaps);

            var associationSetMapping
                = new AssociationSetMapping(
                    new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), entityContainerMapping);

            entityContainerMapping.AddSetMapping(associationSetMapping);

            Assert.Same(associationSetMapping, entityContainerMapping.AssociationSetMappings.Single());
            Assert.Same(associationSetMapping, entityContainerMapping.RelationshipSetMaps.Single());
        }
        public void Can_get_entity_set_mappings()
        {
            var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));

            Assert.Empty(entityContainerMapping.EntitySetMappings);
            Assert.Empty(entityContainerMapping.EntitySetMaps);

            var entitySetMapping
                = new EntitySetMapping(
                    new EntitySet("ES", null, null, null, new EntityType("E", "N", DataSpace.CSpace)), entityContainerMapping);

            entityContainerMapping.AddSetMapping(entitySetMapping);

            Assert.Same(entitySetMapping, entityContainerMapping.EntitySetMappings.Single());
            Assert.Same(entitySetMapping, entityContainerMapping.EntitySetMaps.Single());
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var conceptualContainer = new EntityContainer("C", DataSpace.CSpace);
            var storeContainer = new EntityContainer("S", DataSpace.CSpace);
            var containerMapping = new EntityContainerMapping(conceptualContainer, storeContainer, null, false);

            var entitySet
                = new EntitySet(
                    "ES", "S", "T", "Q",
                    new EntityType("ET", "N", DataSpace.SSpace));
            var entitySetMapping = new EntitySetMapping(entitySet, containerMapping);
            var associationSetMapping
                = new AssociationSetMapping(
                    new AssociationSet(
                        "AS",
                        new AssociationType("AT", "N", false, DataSpace.CSpace)),
                    entitySet);
            var functionImporMapping 
                = new FunctionImportMappingFake(
                    new EdmFunction("FI", "N", DataSpace.CSpace),
                    new EdmFunction("TF", "N", DataSpace.SSpace));

            containerMapping.AddSetMapping(entitySetMapping);
            containerMapping.AddSetMapping(associationSetMapping);
            containerMapping.AddFunctionImportMapping(functionImporMapping);

            Assert.False(containerMapping.IsReadOnly);
            Assert.False(entitySetMapping.IsReadOnly);
            Assert.False(associationSetMapping.IsReadOnly);
            Assert.False(functionImporMapping.IsReadOnly);

            containerMapping.SetReadOnly();

            Assert.True(containerMapping.IsReadOnly);
            Assert.True(entitySetMapping.IsReadOnly);
            Assert.True(associationSetMapping.IsReadOnly);
            Assert.True(functionImporMapping.IsReadOnly);
        }
        public void GenerateViews_generates_views_for_all_containers_that_contain_mappings()
        {
            var storageMappingItemCollection = 
                CreateStorageMappingItemCollection(new[] { Ssdl, SchoolSsdl }, new[] { Csdl, SchoolCsdl }, new[] { Msl});

            // Add second container mapping without type mappings.
            var conceptualEntityContainer = storageMappingItemCollection.EdmItemCollection.GetItems<EntityContainer>()[1];
            var storeEntityContainer = storageMappingItemCollection.StoreItemCollection.GetItems<EntityContainer>()[1];
            var storeEntitySet = storeEntityContainer.EntitySets.First();

            var containerMapping = new EntityContainerMapping(
                conceptualEntityContainer, storeEntityContainer, storageMappingItemCollection, false);

            var entitySetMapping = new EntitySetMapping(storeEntitySet, containerMapping);
            containerMapping.AddSetMapping(entitySetMapping);

            containerMapping.SetReadOnly();
            storageMappingItemCollection.AddInternal(containerMapping);

            var errors = new List<EdmSchemaError>();
            var views = storageMappingItemCollection.GenerateViews("AdventureWorksEntities3", "AdventureWorksModelStoreContainer", errors);

            Assert.Empty(errors);
            Assert.Equal(2, views.Count);

            errors = new List<EdmSchemaError>();
            views = storageMappingItemCollection.GenerateViews("SchoolContainer", "SchoolStoreContainer", errors);

            Assert.Empty(errors);
            Assert.Equal(0, views.Count);
        }