Exemplo n.º 1
0
        public void Configure_should_update_table_name_when_base_type_is_null()
        {
            var entityMappingConfiguration
                = new EntityMappingConfiguration
                      {
                          TableName = new DatabaseName("Foo")
                      };

            var entityTypeMapping = new StorageEntityTypeMapping(null);

            entityTypeMapping.AddType(new EntityType("E", "N", DataSpace.CSpace));

            var databaseMapping =
                new DbDatabaseMapping().Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));

            var table = databaseMapping.Database.AddTable("foo");
            var entitySet = databaseMapping.Database.GetEntitySet(table);

            entityTypeMapping.AddFragment(new StorageMappingFragment(entitySet, entityTypeMapping, false));
            
            entityMappingConfiguration.Configure(
                databaseMapping, ProviderRegistry.Sql2008_ProviderManifest, entityTypeMapping.EntityType, ref entityTypeMapping, false, 0, 1);

            Assert.Equal("Foo", table.GetTableName().Name);
        }
Exemplo n.º 2
0
        public static void GetIdentity_of_StorageEntityTypeMapping_returns_expected_value()
        {
            var entityType1 = new EntityType("ET1", "N", DataSpace.CSpace);
            var entityType2 = new EntityType("ET2", "N", DataSpace.CSpace);
            var entityType3 = new EntityType("ET3", "N", DataSpace.CSpace);
            var entityType4 = new EntityType("ET4", "N", DataSpace.CSpace);
            var mapping     = new StorageEntityTypeMapping(null);

            mapping.AddType(entityType2);
            mapping.AddType(entityType1);
            mapping.AddIsOfType(entityType4);
            mapping.AddIsOfType(entityType3);

            Assert.Equal("N.ET1,N.ET2,N.ET3,N.ET4",
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity((StorageTypeMapping)mapping));
        }
Exemplo n.º 3
0
        public static void GetIdentity_of_StorageMappingFragment_returns_expected_value()
        {
            var entityType        = new EntityType("ET", "N", DataSpace.CSpace);
            var entitySet         = new EntitySet("ES", "S", "T", null, entityType);
            var entityTypeMapping = new StorageEntityTypeMapping(null);

            entityTypeMapping.AddType(entityType);
            var mappingFragment = new StorageMappingFragment(entitySet, entityTypeMapping, false);

            Assert.Equal(entitySet.Identity,
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mappingFragment));
        }
        public void AddType_throws_for_null_type()
        {
            var entityTypeMapping
                = new StorageEntityTypeMapping(
                    new StorageEntitySetMapping(
                        new EntitySet(), 
                        new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.Equal(
                "type",
                Assert.Throws<ArgumentNullException>(() => entityTypeMapping.AddType(null)).ParamName);
        }
        public static StorageEntityTypeMapping Clone(this StorageEntityTypeMapping entityTypeMapping)
        {
            DebugCheck.NotNull(entityTypeMapping);

            var clone = new StorageEntityTypeMapping(null);

            clone.AddType(entityTypeMapping.EntityType);

            entityTypeMapping.Annotations.Copy(clone.Annotations);

            return clone;
        }
        public void AddType_throws_for_null_type()
        {
            var entityTypeMapping
                = new StorageEntityTypeMapping(
                      new StorageEntitySetMapping(
                          new EntitySet(),
                          new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.Equal(
                "type",
                Assert.Throws <ArgumentNullException>(() => entityTypeMapping.AddType(null)).ParamName);
        }
        public void Can_get_entity_type()
        {
            var entityTypeMapping
                = new StorageEntityTypeMapping(
                      new StorageEntitySetMapping(new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.Null(entityTypeMapping.EntityType);

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            entityTypeMapping.AddType(entityType);

            Assert.Same(entityType, entityTypeMapping.EntityType);
        }
        public void Can_get_entity_type()
        {
            var entityTypeMapping 
                = new StorageEntityTypeMapping(
                    new StorageEntitySetMapping(new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.Null(entityTypeMapping.EntityType);

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            entityTypeMapping.AddType(entityType);

            Assert.Same(entityType, entityTypeMapping.EntityType);
        }
        public void Added_type_returned_in_type_collection()
        {
            var entityTypeMapping
                = new StorageEntityTypeMapping(
                    new StorageEntitySetMapping(
                        new EntitySet(),
                        new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.Empty(entityTypeMapping.Types);
            Assert.Empty(entityTypeMapping.IsOfTypes);

            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            
            entityTypeMapping.AddType(entityType);

            Assert.Same(entityType, entityTypeMapping.Types.Single());
            Assert.Empty(entityTypeMapping.IsOfTypes);
        }
        public void Added_type_returned_in_type_collection()
        {
            var entityTypeMapping
                = new StorageEntityTypeMapping(
                      new StorageEntitySetMapping(
                          new EntitySet(),
                          new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.Empty(entityTypeMapping.Types);
            Assert.Empty(entityTypeMapping.IsOfTypes);

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            entityTypeMapping.AddType(entityType);

            Assert.Same(entityType, entityTypeMapping.Types.Single());
            Assert.Empty(entityTypeMapping.IsOfTypes);
        }
        public void Can_create_hierarchy_mappings()
        {
            var entityTypeMapping
                = new StorageEntityTypeMapping(
                      new StorageEntitySetMapping(new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.False(entityTypeMapping.IsHierarchyMapping);

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            entityTypeMapping.AddType(entityType);
            entityTypeMapping.AddIsOfType(entityType);

            Assert.True(entityTypeMapping.IsHierarchyMapping);

            entityTypeMapping.RemoveIsOfType(entityType);

            Assert.False(entityTypeMapping.IsHierarchyMapping);
        }
        public void Can_create_hierarchy_mappings()
        {
            var entityTypeMapping
                = new StorageEntityTypeMapping(
                    new StorageEntitySetMapping(new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));

            Assert.False(entityTypeMapping.IsHierarchyMapping);

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            entityTypeMapping.AddType(entityType);
            entityTypeMapping.AddIsOfType(entityType);

            Assert.True(entityTypeMapping.IsHierarchyMapping);

            entityTypeMapping.RemoveIsOfType(entityType);

            Assert.False(entityTypeMapping.IsHierarchyMapping);
        }
        public void Generate(EntityType entityType, DbDatabaseMapping databaseMapping)
        {
            DebugCheck.NotNull(entityType);
            DebugCheck.NotNull(databaseMapping);

            var entitySet = databaseMapping.Model.GetEntitySet(entityType);

            var entitySetMapping
                = databaseMapping.GetEntitySetMapping(entitySet)
                  ?? databaseMapping.AddEntitySetMapping(entitySet);

            var table
                = entitySetMapping.EntityTypeMappings.Any()
                      ? entitySetMapping.EntityTypeMappings.First().MappingFragments.First().Table
                      : databaseMapping.Database.AddTable(entityType.GetRootType().Name);

            var entityTypeMapping = new StorageEntityTypeMapping(null);

            var entityTypeMappingFragment
                = new StorageMappingFragment(databaseMapping.Database.GetEntitySet(table), entityTypeMapping, false);

            entityTypeMapping.AddType(entityType);
            entityTypeMapping.AddFragment(entityTypeMappingFragment);
            entityTypeMapping.SetClrType(entityType.GetClrType());

            entitySetMapping.AddTypeMapping(entityTypeMapping);

            new PropertyMappingGenerator(_providerManifest)
                .Generate(
                    entityType,
                    entityType.Properties,
                    entitySetMapping,
                    entityTypeMappingFragment,
                    new List<EdmProperty>(),
                    false);
        }
        public void Generate_should_exclude_sgp_properties_from_corresponding_function_mappings()
        {
            var functionMappingGenerator
                = new ModificationFunctionMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            var databaseMapping
                = new DbDatabaseMapping()
                    .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            var intProperty = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
            intProperty.SetStoreGeneratedPattern(StoreGeneratedPattern.Identity);
            entityType.AddKeyMember(intProperty);

            var stringProperty = EdmProperty.Primitive("Name", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            stringProperty.SetStoreGeneratedPattern(StoreGeneratedPattern.Computed);
            entityType.AddMember(stringProperty);

            var entitySetMapping
                = databaseMapping.AddEntitySetMapping(
                    databaseMapping.Model.AddEntitySet("ES", entityType));

            var storageEntityTypeMapping
                = new StorageEntityTypeMapping(
                    new StorageEntitySetMapping(new EntitySet(), databaseMapping.EntityContainerMappings.Single()));

            storageEntityTypeMapping.AddType(entityType);

            var storageMappingFragment = new StorageMappingFragment(new EntitySet(), storageEntityTypeMapping, false);

            storageMappingFragment.AddColumnMapping(
                new ColumnMappingBuilder(new EdmProperty("C0"), new[] { intProperty }));

            storageMappingFragment.AddColumnMapping(
                new ColumnMappingBuilder(new EdmProperty("C1"), new[] { stringProperty }));

            storageEntityTypeMapping.AddFragment(storageMappingFragment);

            entitySetMapping.AddTypeMapping(storageEntityTypeMapping);

            functionMappingGenerator.Generate(entityType, databaseMapping);

            var modificationFunctionMapping
                = entitySetMapping.ModificationFunctionMappings.Single();

            Assert.NotNull(modificationFunctionMapping);

            var functionMapping = modificationFunctionMapping.InsertFunctionMapping;

            Assert.NotNull(functionMapping);
            Assert.Equal(0, functionMapping.ParameterBindings.Count);
            Assert.Equal(2, functionMapping.ResultBindings.Count);

            var function = functionMapping.Function;

            Assert.NotNull(function);
            Assert.Equal("E_Insert", function.Name);
            Assert.Equal(0, function.Parameters.Count);

            functionMapping = modificationFunctionMapping.UpdateFunctionMapping;

            Assert.NotNull(functionMapping);
            Assert.Equal(1, functionMapping.ParameterBindings.Count);
            Assert.Equal(1, functionMapping.ResultBindings.Count);

            function = functionMapping.Function;

            Assert.NotNull(function);
            Assert.Equal("E_Update", function.Name);
            Assert.Equal(1, function.Parameters.Count);

            functionMapping = modificationFunctionMapping.DeleteFunctionMapping;

            Assert.NotNull(functionMapping);
            Assert.Equal(1, functionMapping.ParameterBindings.Count);
            Assert.Null(functionMapping.ResultBindings);

            function = modificationFunctionMapping.DeleteFunctionMapping.Function;

            Assert.NotNull(function);
            Assert.Equal("E_Delete", function.Name);
            Assert.Equal(1, function.Parameters.Count);
        }
        public static void GetIdentity_of_StorageMappingFragment_returns_expected_value()
        {
            var entityType = new EntityType("ET", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", "S", "T", null, entityType);
            var entityTypeMapping = new StorageEntityTypeMapping(null);
            entityTypeMapping.AddType(entityType);
            var mappingFragment = new StorageMappingFragment(entitySet, entityTypeMapping, false);

            Assert.Equal(entitySet.Identity,
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mappingFragment));
        }
Exemplo n.º 16
0
        public void GetEntityTypeMapping_should_return_mapping_for_type()
        {
            var databaseMapping = new DbDatabaseMapping()
                .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entityTypeMapping = new StorageEntityTypeMapping(null);
            entityTypeMapping.AddType(entityType);
            databaseMapping.AddEntitySetMapping(
                new EntitySet
                    {
                        Name = "ES"
                    }).AddTypeMapping(entityTypeMapping);

            Assert.Same(entityTypeMapping, databaseMapping.GetEntityTypeMapping(entityType));
        }
Exemplo n.º 17
0
        public void GetEntityTypeMapping_should_return_mapping_for_type_by_clrType()
        {
            var databaseMapping = new DbDatabaseMapping()
                .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));
            var entityType = new EntityType("Foo", "N", DataSpace.CSpace);
            var type = typeof(object);

            entityType.Annotations.SetClrType(type);
            var entityTypeMapping = new StorageEntityTypeMapping(null);
            entityTypeMapping.AddType(entityType);
            entityTypeMapping.SetClrType(typeof(object));
            databaseMapping.AddEntitySetMapping(
                new EntitySet
                    {
                        Name = "ES"
                    }).AddTypeMapping(entityTypeMapping);

            Assert.Same(entityTypeMapping, databaseMapping.GetEntityTypeMapping(typeof(object)));
        }
        public static void GetIdentity_of_StorageEntityTypeMapping_returns_expected_value()
        {
            var entityType1 = new EntityType("ET1", "N", DataSpace.CSpace);
            var entityType2 = new EntityType("ET2", "N", DataSpace.CSpace);
            var entityType3 = new EntityType("ET3", "N", DataSpace.CSpace);
            var entityType4 = new EntityType("ET4", "N", DataSpace.CSpace);
            var mapping = new StorageEntityTypeMapping(null);
            mapping.AddType(entityType2);
            mapping.AddType(entityType1);
            mapping.AddIsOfType(entityType4);
            mapping.AddIsOfType(entityType3);

            Assert.Equal("N.ET1,N.ET2,N.ET3,N.ET4",
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity((StorageTypeMapping)mapping));
        }