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