Skip to content

Pre-model convention configuration overrides foreign key data type #3756

@wdhenrik

Description

@wdhenrik

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();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions