-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
I've used pre-model configuration to default all my strings to a max length of 500 as I don't want MAX columns used everywhere.
HOWEVER, when I create a navigation property, the pre-model convention overrides the data of the foreign key relationship. For example, my primary key is a varchar(10). When referenced as a foreign key, it should also be a varchar(10), but the pre-model convention is applied instead, creating a varchar(500).
A foreign key column should match the primary key definition exactly. With the current implementation, using pre-model convention requires the foreign key column and type to be explicitly declared, requiring additional code, unnecessarily duplicating the defintion, and introducing a possible point of failure if they are not kept in synch.
I would prefer that foreign keys are excluded from pre-model configuration. If that is not an option, I would like to see an additional flag added to the configuration builder to prioritize the key data type in a relationship
configurationBuilder
.Properties<string>()
.HaveMaxLength(500)
.AreUnicode(false)
//suggestion
.PreferTypeFromKey();