private bool ConfigureTableType(Type clrType) { var mapping = GetDefaultMapping(clrType); Type existingType; if (configuredEntityTypes.TryGetValue(mapping.TableName.ToLowerInvariant(), out existingType) && existingType != clrType) { string newTypeSchema = EntityTypeDiscovery.DetectEntitySchemaSpace(clrType); string existingTypeSchema = EntityTypeDiscovery.DetectEntitySchemaSpace(existingType); if (newTypeSchema != CurrentSchemaSpace) { return(false); } else if (existingTypeSchema != CurrentSchemaSpace) { var existingTypeConfiguration = entityTypeConfigurations[existingType]; //existingTypeConfiguration.Ignore(); //fugly hack, something's probably changed in EF object entityTypeConfigurationFieldVal = existingTypeConfiguration.GetType() .GetField("_entityTypeConfiguration", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(existingTypeConfiguration); object complexTypeConfigurationFieldVal = existingTypeConfiguration.GetType() .GetField("_complexTypeConfiguration", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(existingTypeConfiguration); //if (entityTypeConfigurationFieldVal == null && complexTypeConfigurationFieldVal == null) //{ /*ModelConfiguration*/ object modelConfigurationFieldVal = existingTypeConfiguration.GetType() .GetField("_modelConfiguration", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(existingTypeConfiguration); modelConfigurationFieldVal.GetType().GetMethod("Ignore") .Invoke(modelConfigurationFieldVal, new[] { existingType }); //} entityTypeConfigurations.Remove(existingType); configuredEntityTypes.Remove(mapping.TableName.ToLowerInvariant()); } else { throw new InvalidOperationException("Conflicting entity types"); } } if (!configuredEntityTypes.ContainsKey(clrType.Name.ToLowerInvariant())) { configuredEntityTypes.Add(clrType.Name.ToLowerInvariant(), clrType); } if (!configuredEntityTypes.ContainsKey(mapping.TableName.ToLowerInvariant())) { configuredEntityTypes.Add(mapping.TableName.ToLowerInvariant(), clrType); } return(true); }
public ModelMetadataExplorer(EntityTypeDiscovery entityTypeDiscovery, IDbContextFactory dbContextFactory) { this.entityTypeDiscovery = entityTypeDiscovery; this.dbContextFactory = dbContextFactory; }