This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IServiceCollection InitDatabaseContext(this IServiceCollection services, string connectionString) | |
{ | |
services.AddDbContext<AppDbContext>(opts => | |
{ | |
opts.UseSqlServer(connectionString); | |
opts.ReplaceService<IConventionSetBuilder, CustomSetBuilder>(); | |
}); | |
return services; | |
} | |
public class CustomSetBuilder : SqlServerConventionSetBuilder | |
{ | |
public CustomSetBuilder(RelationalConventionSetBuilderDependencies dependencies, ISqlGenerationHelper sqlGenerationHelper) : base(dependencies, sqlGenerationHelper) | |
{ | |
} | |
public override ConventionSet AddConventions(ConventionSet conventionSet) | |
{ | |
var et = conventionSet.ForeignKeyAddedConventions.FirstOrDefault(f => f is ForeignKeyIndexConvention); | |
if (et != null) | |
conventionSet.ForeignKeyAddedConventions.Remove(et); | |
return base.AddConventions(conventionSet); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment