public void Configure_should_update_table_name_when_base_type_is_null() { var entityMappingConfiguration = new EntityMappingConfiguration { TableName = new DatabaseName("Foo") }; var entityTypeMapping = new EntityTypeMapping(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 MappingFragment(entitySet, entityTypeMapping, false)); entityMappingConfiguration.Configure( databaseMapping, ProviderRegistry.Sql2008_ProviderManifest, entityTypeMapping.EntityType, ref entityTypeMapping, false, 0, 1, new Dictionary <string, object>()); Assert.Equal("Foo", table.GetTableName().Name); }
public static EntityTypeMapping Clone(this EntityTypeMapping entityTypeMapping) { EntityTypeMapping entityTypeMapping1 = new EntityTypeMapping((EntitySetMapping)null); entityTypeMapping1.AddType(entityTypeMapping.EntityType); entityTypeMapping.Annotations.Copy((ICollection <MetadataProperty>)entityTypeMapping1.Annotations); return(entityTypeMapping1); }
public static EntityTypeMapping Clone(this EntityTypeMapping entityTypeMapping) { DebugCheck.NotNull(entityTypeMapping); var clone = new EntityTypeMapping(null); clone.AddType(entityTypeMapping.EntityType); entityTypeMapping.Annotations.Copy(clone.Annotations); return(clone); }
public void Generate(EntityType entityType, DbDatabaseMapping databaseMapping) { EntitySet entitySet = databaseMapping.Model.GetEntitySet(entityType); EntitySetMapping entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet) ?? databaseMapping.AddEntitySetMapping(entitySet); EntityTypeMapping entityTypeMapping1 = entitySetMapping.EntityTypeMappings.FirstOrDefault <EntityTypeMapping>((Func <EntityTypeMapping, bool>)(m => m.EntityTypes.Contains((EntityTypeBase)entitySet.ElementType))) ?? entitySetMapping.EntityTypeMappings.FirstOrDefault <EntityTypeMapping>(); EntityType entityType1 = entityTypeMapping1 != null?entityTypeMapping1.MappingFragments.First <MappingFragment>().Table : databaseMapping.Database.AddTable(entityType.GetRootType().Name); EntityTypeMapping entityTypeMapping2 = new EntityTypeMapping((EntitySetMapping)null); MappingFragment mappingFragment = new MappingFragment(databaseMapping.Database.GetEntitySet(entityType1), (TypeMapping)entityTypeMapping2, false); entityTypeMapping2.AddType(entityType); entityTypeMapping2.AddFragment(mappingFragment); entityTypeMapping2.SetClrType(EntityTypeExtensions.GetClrType(entityType)); entitySetMapping.AddTypeMapping(entityTypeMapping2); new PropertyMappingGenerator(this._providerManifest).Generate(entityType, (IEnumerable <EdmProperty>)entityType.Properties, entitySetMapping, mappingFragment, (IList <EdmProperty>) new List <EdmProperty>(), false); }
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 EntityTypeMapping(null); entityTypeMapping.AddType(entityType); databaseMapping.AddEntitySetMapping( new EntitySet { Name = "ES" }).AddTypeMapping(entityTypeMapping); Assert.Same(entityTypeMapping, databaseMapping.GetEntityTypeMapping(entityType)); }
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.GetMetadataProperties().SetClrType(type); var entityTypeMapping = new EntityTypeMapping(null); entityTypeMapping.AddType(entityType); entityTypeMapping.SetClrType(typeof(object)); databaseMapping.AddEntitySetMapping( new EntitySet { Name = "ES" }).AddTypeMapping(entityTypeMapping); Assert.Same(entityTypeMapping, databaseMapping.GetEntityTypeMapping(typeof(object))); }
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 entityTypeMapping = entitySetMapping.EntityTypeMappings.FirstOrDefault( m => m.EntityTypes.Contains(entitySet.ElementType)) ?? entitySetMapping.EntityTypeMappings.FirstOrDefault(); var table = entityTypeMapping != null ? entityTypeMapping.MappingFragments.First().Table : databaseMapping.Database.AddTable(entityType.GetRootType().Name); entityTypeMapping = new EntityTypeMapping(null); var entityTypeMappingFragment = new MappingFragment(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); }
BuildEntityTypeMapping(EntitySetMapping storeEntitySetMapping, SimpleMappingContext mappingContext, EntitySet storeEntitySet) { Debug.Assert(storeEntitySetMapping != null, "storeEntitySetMapping != null"); Debug.Assert(mappingContext != null, "mappingContext != null"); var entityType = storeEntitySetMapping.EntitySet.ElementType; var entityTypeMapping = new EntityTypeMapping(storeEntitySetMapping); entityTypeMapping.AddType(entityType); var mappingFragment = new MappingFragment(storeEntitySet, entityTypeMapping, false); entityTypeMapping.AddFragment(mappingFragment); foreach (var propertyMapping in BuildPropertyMapping(storeEntitySet.ElementType, mappingContext)) { mappingFragment.AddColumnMapping(propertyMapping); } return(entityTypeMapping); }
public void Can_generate_function_mappings_for_entity_type() { 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.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); entityType.AddKeyMember(intProperty); var stringProperty = EdmProperty.CreatePrimitive("Name", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(stringProperty); var entitySetMapping = databaseMapping.AddEntitySetMapping( databaseMapping.Model.AddEntitySet("ES", entityType)); var storageEntityTypeMapping = new EntityTypeMapping( new EntitySetMapping(new EntitySet(), databaseMapping.EntityContainerMappings.Single())); storageEntityTypeMapping.AddType(entityType); var storageMappingFragment = new MappingFragment(new EntitySet(), storageEntityTypeMapping, false); storageMappingFragment.AddColumnMapping( new ColumnMappingBuilder(new EdmProperty("C0", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), new[] { intProperty })); storageMappingFragment.AddColumnMapping( new ColumnMappingBuilder(new EdmProperty("C1", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), 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(2, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); var function = functionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Insert", function.Name); Assert.Equal(2, function.Parameters.Count); functionMapping = modificationFunctionMapping.UpdateFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(2, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); function = functionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Update", function.Name); Assert.Equal(2, 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); }