public void Can_add_and_get_entity_type_mapping()
        {
            var e1 = CreateEntityType("e1");
            var e2 = CreateEntityType("e2");

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);
            Assert.Empty(mappingContext.ConceptualEntityTypes());
            mappingContext.AddMapping(e1, e2);
            Assert.Same(e2, mappingContext[e1]);
            Assert.Same(e2, mappingContext.ConceptualEntityTypes().Single());
        }
        public void Can_add_and_get_entity_type_mapping()
        {
            var e1 = CreateEntityType("e1");
            var e2 = CreateEntityType("e2");

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

            Assert.Empty(mappingContext.ConceptualEntityTypes());
            mappingContext.AddMapping(e1, e2);
            Assert.Same(e2, mappingContext[e1]);
            Assert.Same(e2, mappingContext.ConceptualEntityTypes().Single());
        }
예제 #3
0
        private static EdmModel BuildEntityModel(SimpleMappingContext mappingContext)
        {
            var conceptualModelContainer = mappingContext[mappingContext.StoreModel.Containers.Single()];
            var entityModel = EdmModel.CreateConceptualModel(conceptualModelContainer, mappingContext.StoreModel.SchemaVersion);

            foreach (var entityType in mappingContext.ConceptualEntityTypes())
            {
                entityModel.AddItem(entityType);
            }

            foreach (var associationSet in mappingContext.ConceptualAssociationSets())
            {
                entityModel.AddItem(associationSet.ElementType);
            }

            foreach (var mappedStoredFunction in mappingContext.MappedStoreFunctions())
            {
                var functionImport = mappingContext[mappedStoredFunction];
                entityModel.AddItem(
                    (ComplexType)
                    ((CollectionType)functionImport.ReturnParameter.TypeUsage.EdmType).TypeUsage.EdmType);
            }

            return(entityModel);
        }
        private static EdmModel BuildEntityModel(SimpleMappingContext mappingContext)
        {
            var conceptualModelContainer = mappingContext[mappingContext.StoreModel.Containers.Single()];
            var entityModel = EdmModel.CreateConceptualModel(conceptualModelContainer, mappingContext.StoreModel.SchemaVersion);

            foreach (var entityType in mappingContext.ConceptualEntityTypes())
            {
                entityModel.AddItem(entityType);
            }

            foreach (var associationSet in mappingContext.ConceptualAssociationSets())
            {
                entityModel.AddItem(associationSet.ElementType);
            }

            foreach (var mappedStoredFunction in mappingContext.MappedStoreFunctions())
            {
                var functionImport = mappingContext[mappedStoredFunction];
                entityModel.AddItem(
                    (ComplexType)
                    ((CollectionType)functionImport.ReturnParameter.TypeUsage.EdmType).TypeUsage.EdmType);
            }

            return entityModel;
        }
        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());
        }
        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());
        }