Decorate your domain model with System.ComponentModel.DataAnnotations.StringLengthAttribute
such as
[StringLengthAttribute(8001)]
public string Markdown { get;set; }
or
[StringLength(Int32.MaxValue)]
public string Markdown { get;set; }
using any length greater than 8000 to exceed to maximum length of Sql Server varchar
/nvarchar
column types that required the MAX
declaration.
Use a custom dialect provider the understands the MAX
declaration.
public class MaxSqlProvider : SqlServerOrmLiteDialectProvider
{
public new static readonly MaxSqlProvider Instance = new MaxSqlProvider ();
public override string GetColumnDefinition(string fieldName, Type fieldType,
bool isPrimaryKey, bool autoIncrement, bool isNullable,
int? fieldLength, int? scale, string defaultValue)
{
var fieldDefinition = base.GetColumnDefinition(fieldName, fieldType,
isPrimaryKey, autoIncrement, isNullable,
fieldLength, scale, defaultValue);
if (fieldType == typeof (string) && fieldLength > 8000)
{
var orig = string.Format(StringLengthColumnDefinitionFormat, fieldLength);
var max = string.Format(StringLengthColumnDefinitionFormat, "MAX");
fieldDefinition = fieldDefinition.Replace(orig, max);
}
return fieldDefinition;
}
}
Use the provider when you construct the database factory
var dbFactory = new OrmLiteConnectionFactory(conStr, MaxSqlProvider.Instance);
Note this illustration is specifically targeting SqlServer but it would be relevant for other data providers with minor alterations after inheriting from the desired provider.