我创建了表
private static void CreateTable(SchemaBuilder builder) {
builder.CreateTable(typeof(RkeeperV7MenuRecord).Name, table => table
.Column<int>("Id", c => c.PrimaryKey().Identity())
.Column<int>("SpotId", c => c.NotNull())
.Column<DateTime>("Date", c => c.NotNull())
.Column<string>("OriginalData", c => c.NotNull().Unlimited())
);
创建了SQL Server数据库中的表(并且字符串在legth属性中具有max)。如果我从DB服务器生成SQL表脚本,它将是这样的(所以字符串被标记为无限制)
CREATE TABLE [dbo].[Plus_Plus_SpotServerIntegration_Rkeeper_RkeeperV7MenuRecord](
[Id] [int] IDENTITY(1,1) NOT NULL,
[SpotId] [int] NOT NULL,
[Date] [datetime] NOT NULL,
[OriginalData] [nvarchar](max) NOT 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]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
但是...当我尝试在表中插入记录时,nhibernate抛出异常“错误使Plus.SpotServerIntegration.Rkeeper.Models.RkeeperV7MenuRecord.OriginalData的属性值脱水”并且内部异常是“字符串值的长度超过了在映射/参数中配置的长度。“ 我该怎么做才能插入记录?
PS string大约是100000个符号(它是xml)
_rkeeperV7MenuRepositiory.Create(new RkeeperV7MenuRecord {
OriginalData = model.OriginalData,
SpotId = spot.Id,
Date = _clock.UtcNow
});
,其中
private readonly IRepository<RkeeperV7MenuRecord> _rkeeperV7MenuRepositiory;
答案 0 :(得分:2)
知道了! 应按照属性“StringLengthMax”标记属性记录,如此
public class RkeeperV7MenuRecord : DefaultEntityRecord {
public virtual int SpotId { get; set; }
public virtual DateTime Date { get; set; }
[StringLengthMax]
public virtual string OriginalData { get; set; }
}