Example #1
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 ConceptualAssociationSets_returns_associationsets_for_collapsed_entity_sets()
        {
            var storeEntity               = CreateEntityType("storeEntity");
            var storeEntitySet            = EntitySet.Create("storeEntitySet", null, null, null, storeEntity, null);
            var collapsibleAssociationSet = new CollapsibleEntityAssociationSets(storeEntitySet);

            var associationType = AssociationType.Create("modelAssociationType", "ns", false, DataSpace.CSpace, null, null, null, null);
            var associationSet  = AssociationSet.Create("modelAssociationType", associationType, null, null, null);

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

            Assert.Empty(mappingContext.ConceptualAssociationSets());

            mappingContext.AddMapping(collapsibleAssociationSet, associationSet);
            Assert.Equal(1, mappingContext.ConceptualAssociationSets().Count());
            Assert.Same(associationSet, mappingContext.ConceptualAssociationSets().Single());
        }
Example #4
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 ConceptualAssociationSets_returns_associationsets_for_collapsed_entity_sets()
        {
            var storeEntity = CreateEntityType("storeEntity");
            var storeEntitySet = EntitySet.Create("storeEntitySet", null, null, null, storeEntity, null);
            var collapsibleAssociationSet = new CollapsibleEntityAssociationSets(storeEntitySet);

            var associationType = AssociationType.Create("modelAssociationType", "ns", false, DataSpace.CSpace, null, null, null, null);
            var associationSet = AssociationSet.Create("modelAssociationType", associationType, null, null, null);

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

            mappingContext.AddMapping(collapsibleAssociationSet, associationSet);
            Assert.Equal(1, mappingContext.ConceptualAssociationSets().Count());
            Assert.Same(associationSet, mappingContext.ConceptualAssociationSets().Single());
        }