我的传奇课程如下:
public class SagaData : IContainSagaData
{
[Unique]
public virtual string SagaKey { get; set; }
public virtual string Data { get; set; }
#region IContainSagaData
public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
#endregion IContainSagaData
}
我在MSSQL中坚持Sagas。创建的表具有以下结构:
CREATE TABLE [dbo].[SagaData](
[Id] [uniqueidentifier] NOT NULL,
[SagaKey] [nvarchar](255) NULL,
[Data] [nvarchar](255) NULL,
[Originator] [nvarchar](255) NULL,
[OriginalMessageId] [nvarchar](255) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED
(
[SagaKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Data
属性(字符串类型)已映射到nvarchar(255)
。显然,当我为该属性分配超过255个字符时,它会失败并显示消息:String or binary data would be truncated
。我该如何强行制作nvarchar(max)
?
我正在使用NServiceBus 4.4.2。
答案 0 :(得分:0)
解决方案非常简单。我为该类添加了一个HBM文件,将其设置为Embedded Resource,NHibernate自动加载它。这是它的外观:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="LuxMed.BackEnd.CRM.B2C.NSB.Host"
namespace="LuxMed.BackEnd.CRM.B2C.NSB.Host.Sagas">
<class name="SagaData">
<id name="Id" />
<property name="SagaKey" unique="true" />
<property name="Data" type="StringClob" />
<property name="Originator" />
<property name="OriginalMessageId" />
</class>
</hibernate-mapping>
type="StringClob"
是DB中nvarchar(max)
的原因。