String Unlimited仍然限制为4000个字符?

Ani*_*ola 3 c# nhibernate asp.net-mvc orchardcms orchardcms-1.6

我正在使用Orchard 1.6,我正在为我的模块创建零件.我的迁移文件中创建特定表的部分是:

    // Creating table SessionInformationRecord
    SchemaBuilder.CreateTable("SessionInformationRecord", table => table
        .Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
        .Column("TrackInformationRecord_Id", DbType.Int32)
        .Column("Title", DbType.String, col => col.Unlimited())
        .Column("Description", DbType.String, col => col.Unlimited())
        .Column("StartDate", DbType.DateTime)
        .Column("EndDate", DbType.DateTime)
        .Column("HasEvaluation", DbType.Boolean)
        .Column("IsDeleted", DbType.Boolean)
    );
Run Code Online (Sandbox Code Playgroud)

标题和描述应该是无限的字符串.但是,当我输入超过4000个字符的字段的内容时,我收到此错误:

{"@p1 : String truncation: max=4000, len=21588, value=''."}
Run Code Online (Sandbox Code Playgroud)

还有其他方法来解决这个问题吗?或者字符串最多4000个字符?

更新:

除了数据库方面,我还读到你必须在NHibernate端处理它,以确保它不会截断字符串.人们告诉我要添加属性:

[StringLengthMax]
Run Code Online (Sandbox Code Playgroud)

但是,我的模型只识别[StringLength]属性.为了使用[StringLengthMax]属性,我需要导入哪些命名空间或类?

Ani*_*ola 6

虽然底部的答案是正确的,但它们并不完整.

要避免4000字符限制,必须在DB和NHibernate上处理它.

  1. 对于DB,您只需将列定义为无限制,就像我最初完成的那样.确保数据库中的列为nvarchar(max)或varchar(max).

    // Creating table KeynoteInformationRecord
    SchemaBuilder.CreateTable("KeynoteInformationRecord", table => table
        .Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
        .Column("KeynotePartId", DbType.Int32)
        .Column("Title", DbType.String, column => column.Unlimited())
        .Column("Description", DbType.String, column => column.Unlimited())
        .Column("StartDate", DbType.DateTime)
        .Column("EndDate", DbType.DateTime)
        .Column("HasEvaluation", DbType.Boolean)
        .Column("IsDeleted", DbType.Boolean)
    );
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在Nhibernate端,为确保字符串不被截断,您必须将[StringLengthMax]属性添加到模型类中的字符串属性中.在Orchard中,您必须包含Orchard.Data.Conventions才能使用该属性.

见下文:

public class KeynoteInformationRecord
{
    public virtual int Id { get; set; }
    public virtual int KeynotePartId { get; set; }
    [StringLengthMax]
    public virtual string Title { get; set; }
    [StringLengthMax]
    public virtual string Description { get; set; }
    public virtual DateTime StartDate { get; set; }
    public virtual DateTime EndDate { get; set; }
    public virtual bool HasEvaluation { get; set; }
    public virtual bool IsDeleted { get; set; }
}
Run Code Online (Sandbox Code Playgroud)