public void Removing_entity_set_mapping_removes_corresponding_entity_type()
        {
            var storeEntity    = CreateEntityType("storeEntity");
            var modelEntity    = CreateEntityType("modelEntity");
            var storeEntitySet = EntitySet.Create("storeEntitySet", null, null, null, storeEntity, null);
            var modelEntitySet = EntitySet.Create("modelEntitySet", null, null, null, modelEntity, null);

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);

            mappingContext.AddMapping(storeEntity, modelEntity);
            mappingContext.AddMapping(storeEntitySet, modelEntitySet);

            Assert.Same(modelEntitySet, mappingContext.ConceptualEntitySets().Single());
            Assert.Same(modelEntity, mappingContext.ConceptualEntityTypes().Single());

            mappingContext.RemoveMapping(storeEntitySet);

            Assert.Empty(mappingContext.ConceptualEntitySets());
            Assert.Empty(mappingContext.ConceptualEntityTypes());
        }
Пример #2
0
        public SimpleMappingContext Build(EdmModel storeModel)
        {
            Debug.Assert(storeModel != null, "storeModel != null");

            var mappingContext = new SimpleMappingContext(storeModel, _generateForeignKeyProperties);

            var uniqueEntityContainerNames = new UniqueIdentifierService();
            var globallyUniqueTypeNames    = new UniqueIdentifierService();

            CollectForeignKeyProperties(mappingContext, storeModel);

            foreach (var storeEntitySet in storeModel.Containers.Single().EntitySets)
            {
                GenerateEntitySet(mappingContext, storeEntitySet, uniqueEntityContainerNames, globallyUniqueTypeNames);
            }

            GenerateAssociationSets(
                mappingContext,
                uniqueEntityContainerNames,
                globallyUniqueTypeNames);

            var functionImports =
                GenerateFunctions(mappingContext, storeModel, uniqueEntityContainerNames, globallyUniqueTypeNames)
                .ToArray();

            var conceptualModelContainer = EntityContainer.Create(
                _containerName,
                DataSpace.CSpace,
                mappingContext.ConceptualEntitySets()
                .Concat(mappingContext.ConceptualAssociationSets().Cast <EntitySetBase>()),
                functionImports,
                EntityFrameworkVersion.DoubleToVersion(storeModel.SchemaVersion) >= EntityFrameworkVersion.Version2
                    ? new[] { CreateAnnotationMetadataProperty("LazyLoadingEnabled", "true") }
                    : null);

            mappingContext.AddMapping(storeModel.Containers.Single(), conceptualModelContainer);

            return(mappingContext);
        }
        public SimpleMappingContext Build(EdmModel storeModel)
        {
            Debug.Assert(storeModel != null, "storeModel != null");

            var mappingContext = new SimpleMappingContext(storeModel, _generateForeignKeyProperties);

            var uniqueEntityContainerNames = new UniqueIdentifierService();
            var globallyUniqueTypeNames = new UniqueIdentifierService();
            CollectForeignKeyProperties(mappingContext, storeModel);

            foreach (var storeEntitySet in storeModel.Containers.Single().EntitySets)
            {
                GenerateEntitySet(mappingContext, storeEntitySet, uniqueEntityContainerNames, globallyUniqueTypeNames);
            }

            GenerateAssociationSets(
                mappingContext,
                uniqueEntityContainerNames,
                globallyUniqueTypeNames);

            var functionImports =
                GenerateFunctions(mappingContext, storeModel, uniqueEntityContainerNames, globallyUniqueTypeNames)
                    .ToArray();

            var conceptualModelContainer = EntityContainer.Create(
                _containerName,
                DataSpace.CSpace,
                mappingContext.ConceptualEntitySets()
                    .Concat(mappingContext.ConceptualAssociationSets().Cast<EntitySetBase>()),
                functionImports,
                EntityFrameworkVersion.DoubleToVersion(storeModel.SchemaVersion) >= EntityFrameworkVersion.Version2
                    ? new[] { CreateAnnotationMetadataProperty("LazyLoadingEnabled", "true") }
                    : null);

            mappingContext.AddMapping(storeModel.Containers.Single(), conceptualModelContainer);

            return mappingContext;
        }
        public void Removing_entity_set_mapping_removes_corresponding_entity_type()
        {
            var storeEntity = CreateEntityType("storeEntity");
            var modelEntity = CreateEntityType("modelEntity");
            var storeEntitySet = EntitySet.Create("storeEntitySet", null, null, null, storeEntity, null);
            var modelEntitySet = EntitySet.Create("modelEntitySet", null, null, null, modelEntity, null);

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);
            mappingContext.AddMapping(storeEntity, modelEntity);
            mappingContext.AddMapping(storeEntitySet, modelEntitySet);

            Assert.Same(modelEntitySet, mappingContext.ConceptualEntitySets().Single());
            Assert.Same(modelEntity, mappingContext.ConceptualEntityTypes().Single());

            mappingContext.RemoveMapping(storeEntitySet);

            Assert.Empty(mappingContext.ConceptualEntitySets());
            Assert.Empty(mappingContext.ConceptualEntityTypes());
        }