Reputation: 51064
Using a very specific example for ultimately a more general question: How can I configure the column type convention for Code First column generation to use nvarchar(50)
instead of nvarchar(MAX)
for string columns?
Upvotes: 1
Views: 312
Reputation:
You can change the default db type two ways:
Firstly, you can add the appropriate attribute to the property. An annotation of [StringLength(50)]
specifies a length of 50.
Secondly, you can configure the property using the StringPropertyConfiguration
methods.
var entityTypeConfiguration = modelBuilder.Entity<YourEntityType>;
entityTypeConfiguration.Property(t => t.StringProperty).HasMaxLength(50);
You can check the other StringPropertyConfiguration
methods to see what other options are available for configuration.
Upvotes: 1