1

我的 Saga 课程如下:

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 个字符时,它会失败并显示 message: String or binary data would be truncated。我怎么能强迫它nvarchar(max)呢?

我正在使用 NServiceBus 4.4.2。

4

1 回答 1

0

解决方案非常简单。我为该类添加了一个 HBM 文件,将其设置为嵌入式资源,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"是什么nvarchar(max)在数据库中。

于 2014-06-06T08:55:00.283 回答