How to change size of existing column using Entity Framework 6 Code First

喜夏-厌秋 提交于 2020-01-10 04:40:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!