Skip to content

Instantly share code, notes, and snippets.

Created February 12, 2020 15:22
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save giridharprakash/000dd73a290e3275bdcdc35c3fdb3f8c to your computer and use it in GitHub Desktop.
public static IServiceCollection InitDatabaseContext(this IServiceCollection services, string connectionString)
services.AddDbContext<AppDbContext>(opts =>
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)
return base.AddConventions(conventionSet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment