I am experimenting with custom naming convenctions in EF 6. I have 2 tables and one junction table (WebUser, UserRequest, WebUserUserRequest).
I have written function that should be able to rename tables: from WebUser to web_user
private string GetTableName(Type type)
{
var result = Regex.Replace(type.Name, ".[A-Z]", m => m.Value[0] + "_" + m.Value[1]);
return result.ToLower();
}
It is applied this way:
modelBuilder.Types()
.Configure(c => c.ToTable(GetTableName(c.ClrType)));
The function is working fine on all tables except junction tables.
Source models:
WebUser, UserRequest
Resulting DB tables:
web_user, user_request, WebUserUserRequest (instead of web_user_user_request)
Is it possible to set junction naming convenction this way? Is there a way how to configure naming convection to process all the junction tables as described above (replace all uppercase and add "_")?