C# 字符串不受限制仍然限制为4000个字符?
我正在使用Orchard 1.6,我正在为我的模块创建部件。我的迁移文件中创建特定表的部分是:C# 字符串不受限制仍然限制为4000个字符?,c#,asp.net-mvc,nhibernate,orchardcms,orchardcms-1.6,C#,Asp.net Mvc,Nhibernate,Orchardcms,Orchardcms 1.6,我正在使用Orchard 1.6,我正在为我的模块创建部件。我的迁移文件中创建特定表的部分是: // Creating table SessionInformationRecord SchemaBuilder.CreateTable("SessionInformationRecord", table => table .Column("Id", DbType.Int32, column => column.PrimaryKey().Identity()
// 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)
);
标题和描述应该是无限的字符串。但是,当我为超过4000个字符的字段输入内容时,会出现以下错误:
{"@p1 : String truncation: max=4000, len=21588, value=''."}
还有别的办法吗?或者一个字符串的最大值是4000个字符
更新:
除了DB端,我了解到您还必须在NHibernate端处理它,以确保它不会截断字符串。人们告诉我添加属性:
[StringLengthMax]
但是,我的模型只识别[StringLength]属性。要使用[StringLengthMax]属性,我需要导入哪个命名空间或类?此错误来自SQL Server。如果希望字符串更长,则需要修改SQL模式以使用类似于
VARCHAR(MAX)
的内容,这是一个数据库问题
对于SQL Server 2008及更高版本,请使用VARCHAR(MAX)
对于SQL Server 2005及更早版本,您需要明确说明varchar大小,如
varchar(5000)
,其中varchar(8000)
是限制。虽然底部的答案是正确的,但它们并不完整
为了避免4000个字符的限制,必须在DB和NHibernate上处理它
// 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)
);
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; }
}
解决此问题的另一种方法是如下配置地图:
Map(l => l.Description ).CustomType("StringClob").CustomSqlType("varchar(max)");
我目前正在本地/开发机器上使用SQL compact。但是阶段和产品部署都在SQLAzure上。这有什么区别吗?(即sql compact是否有字符限制,即使字符串不受限制?@AnimaSola,是的,4000个字符是sql CE的绝对最大值。还需要将StringLengthMax属性添加到模型属性中。这告诉NHibernate不要截断。同样,对于解决方案,假设我无法控制SQL。但是,我目前正在为本地/开发人员计算机使用SQLCompact。但是阶段和产品部署都在SQLAzure上。这有什么区别吗?(即,即使字符串不受限制,sql compact是否也有字符限制?)对于sql Server compact Edition 4.0,最大字符大小为4000。请阅读SQL Server CE 4.0。注意:
ntext
将是一个选项,但字符串函数不再支持它。您考虑过本地开发环境吗?这将更紧密地反映SQL Azure(您的生产环境)的功能?是的,我有SSM。仅使用compact即可快速部署Orchard。只是想确认这是一个SQL问题,而不是应用程序。谢谢问题是数据库的最大值(xxxx)设置为4000。因为字符串正在解释它。