WithInfiniteLength producing schema update of length 255 instead of max

Thread is closed for posting
2 posts, 0 answers
  1. Musashi
    Musashi avatar
    23 posts
    Member since:
    Jan 2014

    Posted 29 Feb 2016 Link to this post

    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)
        if (isUnicode)
        if (maxLength > 0)

    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:

    Nevertheless, the update script that is generated looks like this:

    -- Column was read from database as: [CMSVALUE] nvarchar(max) null
    -- modify column for field _cMSVALUE


  2. Musashi
    Musashi avatar
    23 posts
    Member since:
    Jan 2014

    Posted 29 Feb 2016 in reply to Musashi Link to this post

    Ok, I found my problem. Specifying my own column type, even if it's correct, overrides the infinite length bit. Reason for specifying my own column type is to handle multiple databases. But if Data Access can fill in the blanks automatically, then I guess I don't need to specify my own column type, at least for strings.
Back to Top