问题
I have a POCO Plant that is mapped to a table dbo.Plant in my DB (SQL SERVER 2014). Some of the columns in the database has the data types nvarchar(max) NULL. I am trying to change the data type via EntityTypeConfiguration using the following code:
Property(x => x.PCode).HasMaxLength(25);
But, when adding the migration (add-migration name), the resulting Up()-method will not contain any changes for this column. However, if I also make it required like this:
Property(x => x.PCode).HasMaxLength(25).IsRequired();
..then the appropriate changes will be made in the Up()-method:
AlterColumn("dbo.Plant", "PCode", c => c.String(nullable: false, maxLength: 25));
Is it possible to get it to register only the change in size without changing the nullability?
Edit: I have managed to come around the problem by making changes directly in the Up() and Down()-methods, but the question remains if there is anything that would trigger this change automatically just using the EntityTypeConfiguration.
来源:https://stackoverflow.com/questions/28299080/how-to-change-size-of-existing-column-using-entity-framework-6-code-first