Assuming you really want NTEXT
. If you want nvarchar(max)
or varchar(max)
see https://stackoverflow.com/a/25729568/37055
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.
Use a custom dialect provider the understands the NTEXT
declaration.
public class NTextSqlProvider : SqlServerOrmLiteDialectProvider
{
public new static readonly NTextSqlProvider Instance = new NTextSqlProvider();
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);
fieldDefinition = fieldDefinition.Replace(orig, "NTEXT");
}
return fieldDefinition;
}
}
Use the provider when you construct the database factory
var dbFactory = new OrmLiteConnectionFactory(conStr, NTextSqlProvider.Instance);