问题描述
我试图插入一些很长的文本到一个字符串prop - 它与LinqToSql完美的工作,现在我已经切换到NHibernate,并希望保存相同的实体,但nHibernate引发上述异常。我如何解决这个问题?
原本我的道具被定义为:
Map(x => x.Content,fT_Content)。Nullable();
Map(x => x.Fields,fT_Fields)。Nullable();
现在他们是:这个工作,但为什么我必须这样做
Map(x => x.Content,fT_Content)。CustomSqlType(nvarchar(max))长度(Int32.MaxValue).Nullable();
Map(x => x.Fields,fT_Fields)。CustomSqlType(nvarchar(max))。Length(Int32.MaxValue).Nullable();
注意:我有最新的nhibernate使用nuget。
$ p
$ b
public virtual string Content
{
get;
set;
}
公共虚拟字符串字段
{
get;
set;
}
我想避免所有突然插入停止工作在这张桌子上....
几年来,我一直在将nvarchar(max)列映射到StringClob,而不会遇到任何问题:
$ p $
< property name =myPropcolumn =MY_PROPnot-null =truetype =StringClobaccess =property >< /性>
这个链接(来自注释)描述了解决此问题所需的流畅映射:
Map(x => x.Description).CustomType(StringClob)。CustomSqlType(nvarchar(max));
I am trying to insert some very long text into a string prop - it worked perfectly fine with LinqToSql, now I have switched over to NHibernate and want to save the same entity, but nHibernate throws the above exception.
How can I fix this?
Originally my props were defined as:
Map(x => x.Content, "fT_Content").Nullable();
Map(x => x.Fields, "fT_Fields").Nullable();
now they are: this works but why do I have to do this?
Map(x => x.Content, "fT_Content").CustomSqlType("nvarchar(max)").Length(Int32.MaxValue).Nullable();
Map(x => x.Fields, "fT_Fields").CustomSqlType("nvarchar(max)").Length(Int32.MaxValue).Nullable();
Note: I have the latest nhibernate using nuget.
For ref here are the fields:
public virtual string Content
{
get;
set;
}
public virtual string Fields
{
get;
set;
}
I want to avoid going to live production and all of a sudden inserts stop working on this table....
This is a well known issue with NHibernate handling nvarchar(max), see :
For some years now, I have been file mapping nvarchar(max) columns to StringClob without encountering any problem :
<property name="myProp" column="MY_PROP" not-null="true" type="StringClob" access="property"></property>
This link (from the comments) describes the fluent mapping required to fix this issue:
http://www.tritac.com/bp-21-fluent-nhibernate-nvarcharmax-fields-truncated-to-4000-characters
Map(x => x.Description).CustomType("StringClob").CustomSqlType("nvarchar(max)");
这篇关于字符串值的长度超过了映射/参数中配置的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!