public void GetEntitySetMappings_should_return_mappings() { var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel().Initialize(), new DbDatabaseMetadata()); databaseMapping.AddAssociationSetMapping(new EdmAssociationSet()); Assert.Equal(1, databaseMapping.GetAssociationSetMappings().Count()); }
private void ConfigureAssociationMappings(DbDatabaseMapping databaseMapping, EdmEntityType entityType) { Contract.Requires(databaseMapping != null); foreach (var configuration in _navigationPropertyConfigurations) { var propertyInfo = configuration.Key; var navigationPropertyConfiguration = configuration.Value; var navigationProperty = entityType.GetNavigationProperty(propertyInfo); if (navigationProperty == null) { throw Error.NavigationPropertyNotFound(propertyInfo.Name, entityType.Name); } var associationSetMapping = databaseMapping.GetAssociationSetMappings() .SingleOrDefault(asm => asm.AssociationSet.ElementType == navigationProperty.Association); if (associationSetMapping != null) { navigationPropertyConfiguration.Configure(associationSetMapping, databaseMapping); } } }
private static void RemoveRedundantTables(DbDatabaseMapping databaseMapping) { Contract.Assert(databaseMapping != null); var tables = (from t in databaseMapping.Database.Schemas.SelectMany(s => s.Tables) where !databaseMapping.GetEntitySetMappings() .SelectMany(esm => esm.EntityTypeMappings) .SelectMany(etm => etm.TypeMappingFragments) .Any(etmf => etmf.Table == t) && !databaseMapping.GetAssociationSetMappings() .Any(asm => asm.Table == t) select t).ToList(); tables.Each( t => { var tableName = t.GetTableName(); if (tableName != null) { throw Error.OrphanedConfiguredTableDetected(tableName); } databaseMapping.Database.RemoveTable(t); }); }