This question is locked. New answers and comments are not allowed.
I have an existing table with a column of type "nvarchar(max) NULL". I'm trying to make sure that my code first metadata doesn't alter anything starting up. But for the life of me I can't figure out why the update code that gets generated makes "nvarchar(255) null".
Here's the method in question.
public static void PrepareStringProperty<T>(this MappingConfiguration<T> configuration, Expression<Func<T, string>> propExp, int maxLength, bool isRequired, bool isUnicode){ string propName = ObjectExtensions.GetPropertyName(propExp); string columnType = isUnicode ? Provider.GetTypeUnicodeString() : Provider.GetTypeString(); var propConfig = configuration.HasProperty(propExp).HasFieldName(FindFieldName<T>(propName)).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(propName).HasColumnType(columnType); if (isRequired) propConfig.IsNotNullable(); else propConfig.IsNullable(); if (isUnicode) propConfig.IsUnicode(); else propConfig.IsNotUnicode(); if (maxLength > 0) propConfig.WithVariableLength(maxLength); else propConfig.WithInfiniteLength();}The supplied parameters are maxLength = 0, isRequired = false, isUnicode = true.
The end result should be a call such as the following, which is verified during debug:
configuration.HasProperty(propExp).HasFieldName(FindFieldName<T>(propName)).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(propName).HasColumnType(columnType).IsNullable().IsUnicode().WithInfiniteLength();
Nevertheless, the update script that is generated looks like this:
-- Column was read from database as: [CMSVALUE] nvarchar(max) null-- modify column for field _cMSVALUEALTER TABLE [CMSTRANS] ALTER COLUMN [CMSVALUE] nvarchar(255) NULL