EF Core Alter Column size automatically

Benjamin Kempe 1 Reputation point
2022-09-06T07:26:23.613+00:00

Is there any way, to resize the column to the needed length in runtime automatically?
for example: the column is a nvarchar(50), but the value to insert has a length of 80. Is it now possible to alter the column to nvarchar(80) by EF Core automatically?
Without EF Core we catch the Fieldlength-Exception and alter the columnsize to the needed length.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
694 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,031 Reputation points
    2022-09-11T01:59:02.36+00:00

    Set the column length to say 255 than use FluentValidation RuleFor to set the length at runtime in a class which inherits AbstractValidator. This of course means you validate before SaveChangess.

    0 comments No comments