Extend my comment earlier ...
If you can just change the name of the table - then go with the display in OnModelCreating - as @Pawel suggested , which is probably the easiest solution for everyone.
However, if you only want to change the name of the relationship,
... by providing a custom SqlGenerator (i.e. SqlServerMigrationSqlGenerator ) in Configuration() , you can micro-control the actual sql generated if necessary (and this could be a general automatic solution in some general case). eg
public class MySqlGenerator : SqlServerMigrationSqlGenerator { protected override void Generate(AddForeignKeyOperation addForeignKeyOperation) { if (addForeignKeyOperation.Name == "LongClassNameOne_TypeConstraint_From_ClassName2s_To_LongClassNameOnes") addForeignKeyOperation.Name = "MyCustomFKName";
... or something in this direction (you need to combine, find the correct name - or compare Name Length and shorten it where necessary. And in your configuration (file created by migrations) ...
public Configuration() { AutomaticMigrationsEnabled = false; SetSqlGenerator("MySQL provider??", new MySqlGenerator());
(note: I don't know what the name of the MySQL provider is)
... this should change the FK relationship - and as fast as you could check it, it works fine, since the name of the relationship is not actually used in the model from C # (just the db name usually).
NSGaga
source share