0

I created table

    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())
            );

and table in SQL Server database was created (and string has max in legth property). If i generate SQL table script from DB server it will be like this (so string is marked as unlimited)

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]

But... When i try to insert record in table, nhibernate throw exception "Error dehydrating property value for Plus.SpotServerIntegration.Rkeeper.Models.RkeeperV7MenuRecord.OriginalData" and inner exception is "The length of the string value exceeds the length configured in the mapping/parameter." What should i do to insert record?

PS string is about 100000 simbols (it is xml)

            _rkeeperV7MenuRepositiory.Create(new RkeeperV7MenuRecord {
                OriginalData = model.OriginalData,
                SpotId = spot.Id,
                Date = _clock.UtcNow
            });

where

private readonly IRepository<RkeeperV7MenuRecord> _rkeeperV7MenuRepositiory;
  • How do you insert data into that table? bulk insert or only a single record?what is the biggest size of OriginalData field? – FLICKER Mar 16 '16 at 16:44
  • answer in question body (string is xml about 100000 simbols and insert operation code) – user2449425 Mar 16 '16 at 17:17
  • please take a look at this link, it may help. http://dba.stackexchange.com/questions/18483/varcharmax-field-cutting-off-data-after-8000-characters-sql-server-2008 – FLICKER Mar 16 '16 at 17:29
  • Possible duplicate of [How to store a non truncated varchar(max) string with NHibernate and Fluent NHibernate](http://stackoverflow.com/questions/3701907/how-to-store-a-non-truncated-varcharmax-string-with-nhibernate-and-fluent-nhib) – Frédéric Mar 16 '16 at 20:31
  • Answer lies in first comment of [currently accepted answer](/a/3702382/1178314) of a same question: call `CustomType("StringClob")`. – Frédéric Mar 16 '16 at 20:36
  • String is NOT truncated. Just insert operation failed (throw an exception). And at the sql server, as i see, table structure and column attributes are correct ([OriginalData] [nvarchar](max)) I checked it. Yes, I know about CustomType("StringClob"), but... I am not sure if it help (operation insert, not table generate is failed) and Orchard CMS has huge wrapper over nhibernate, i think, there is buildin method in Orchard. – user2449425 Mar 16 '16 at 21:10

1 Answers1

2

Got it! Should mark Property record by attribute "StringLengthMax" like this

public class RkeeperV7MenuRecord : DefaultEntityRecord {
    public virtual int SpotId { get; set; }
    public virtual DateTime Date { get; set; }
    [StringLengthMax]
    public virtual string OriginalData { get; set; }
}