Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...