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_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); }