Assuming you really want NTEXT
. If you want nvarchar(max)
or varchar(max)
see https://mcmap.net/q/1022264/-create-a-column-with-varchar-max-rather-than-varchar-8000
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);
text
,ntext
orimage
for new development -- these data types are deprecated. Use, respectively,varchar(MAX)
,nvarchar(MAX)
, andvarbinary(MAX)
. You'll need to consult your ORM documentation for how to use those types. – Logictext
,ntext
andimage
. – Pyle