我正在使用 Nhibernate 并收到特定错误
NHibernate.PropertyValueException: Error dehydrating property value for Models.VehicleDetails---> NHibernate.HibernateException: 字符串值的长度超过映射/参数中配置的长度。
列是数据库中的一个XML列。我已经看到之前提到的这个错误和解决方法字符串值的长度超过了映射/参数中配置的长度但是我使用的是特定的模型类型并且没有运气解决这个问题任何建议都会很好。例如,大多数解决方法都提到使用字符串“StringClob”,但是我有一种类型的 VehicleDetails 。使用下面的映射我仍然遇到错误
Map(x => x.VehicleDetails).CustomType(typeof(CustomUserTypes.XmlColumnObjectType<Models.VehicleDetails>)).CustomSqlType("nvarchar(max)").Column("Vehicle").Length(int.MaxValue);
x => x.VehicleDetails 是一个名为 VehicleDetails 的类,它解析 xml 数据。下面是主要代码,其余只是常规的小方法 CustomUserTypes.XmlColumnObjectType
public class XmlColumnObjectType<TObject> : IUserType where TObject : ICloneable
{
static readonly string sRootName = ReadRootName();
private static string ReadRootName()
{
var attribs = typeof(TObject).GetCustomAttributes(typeof(System.Xml.Serialization.XmlRootAttribute), true);
if (attribs != null && attribs.Length == 1)
{
return (attribs[0] as System.Xml.Serialization.XmlRootAttribute).ElementName;
}
else return typeof(TObject).Name;
}
#region Equals member
public new bool Equals(object x, object y)
{
return (x == y) || ((x != null) && x.Equals(y));
}
public NHibernate.SqlTypes.SqlType[] SqlTypes
{
get { return new NHibernate.SqlTypes.SqlType[] { NHibernate.NHibernateUtil.String.SqlType }; }
}
}