Content Type Needs [StringLengthMax] about Record field and column.Unlimited() in Migrations.cs

Topics: Customizing Orchard, Writing modules
Sep 12, 2012 at 5:21 AM

I'm working on a module that (for now) will be configured by XML pasted into the admin page.

unfortunately the XML can be a little long and I'm not sure but it appears there is a limit in the size accepted by the admin page.  

I can safely save a small portion of it but can't seem to save the full text. Any ideas?  Interestingly enough, I did look at the BodyPart and it's saving it to the database as a string as well so I'm certain Orchard can handle it and I'm doing something wrong.

 

Here is the start of the XML example I'm using

<?xml version="1.0" encoding="UTF-8"?><portfolio>

<categories> <category id="graphic">Graphic 
Design</category> <category id="web">Web Design</category> <category 
id="photo">Photography</category> <category id="video">Videos</category> </categories>
<items>
<item> <thumbnail>http://pexeto.com/tonic_gallery/images/img1.jpg</thumbnail>
<preview>http://pexeto.com/tonic_gallery/images/preview.jpg</preview>
<category>graphic,web,photo</category> <description>Description goes here</description>
</item> <item> <thumbnail>http://pexeto.com/tonic_gallery/images/img5.jpg</thumbnail>

 

Any help would be much appreciated.

Sep 12, 2012 at 6:05 AM

I think I found the issue.  I needed to update the Max size nHibernate uses.  Found it with some creative searching in this post for future reference:

http://orchard.codeplex.com/discussions/270398

Sep 12, 2012 at 6:17 AM
corecomps wrote:

I think I found the issue.  I needed to update the Max size nHibernate uses.  Found it with some creative searching in this post for future reference:

http://orchard.codeplex.com/discussions/270398

Nope, I must have another issue or I'm doing it wrong.  Here is my migration file:

// Creating table PortfolioRecord            SchemaBuilder.CreateTable("PortfolioRecord", table => table                .ContentPartRecord()                .Column<string>("XmlConfig", column => column.Unlimited())                .Column<string>("Parameters", column => column.Unlimited())            );

 

The error is still showing up in the logs:

2012-09-11 22:09:01,645 [6] NHibernate.AdoNet.AbstractBatcher - Could not execute command: UPDATE Core_Portfolios_PortfolioRecord SET XmlConfig = @p0, Parameters = @p1 WHERE Id = @p2System.InvalidOperationException: @p0 : String truncation: max=4000, len=8734, value='

Coordinator
Sep 12, 2012 at 5:36 PM

Are you sure your modifications to your migration ran? What does the column look like in the DB?

Sep 13, 2012 at 1:57 AM
bertrandleroy wrote:

Are you sure your modifications to your migration ran? What does the column look like in the DB?

Unfortunately I am certain it's running them migration (confirmed with breakpoint being hit)

I'm about ready to dig into the database and realized my install of VS 2010 Ultimate appears to be missing SQL Compact 4.0 in my database connectivity list.  How do I get that to show up?

Here is the full error:

2012-09-12 17:35:15,752 [7] NHibernate.AdoNet.AbstractBatcher - Could not execute command: UPDATE Core_Portfolios_PortfolioRecord SET XmlConfig = @p0, Parameters = @p1 WHERE Id = @p2
System.InvalidOperationException: @p0 : String truncation: max=4000, len=8949, value='<!--?xml version="1.0" encoding="UTF-8"?-->


'.
   at System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(Boolean verifyValue)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
2012-09-12 17:35:15,913 [7] Orchard.ContentManagement.DefaultContentManager - InvalidOperationException thrown from IContentHandler by Orchard.Autoroute.Handlers.AutoroutePartHandler
System.InvalidOperationException: @p0 : String truncation: max=4000, len=8949, value='<!--?xml version="1.0" encoding="UTF-8"?-->


'.
   at System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(Boolean verifyValue)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
   at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session)
   at NHibernate.Action.EntityUpdateAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
   at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
   at NHibernate.Impl.SessionImpl.Flush()
   at Orchard.Data.Repository`1.Flush() in C:\Users\John\Source\Repo\src\Orchard\Data\Repository.cs:line 118
   at Orchard.Data.Repository`1.Orchard.Data.IRepository.Flush() in C:\Users\John\Source\Repo\src\Orchard\Data\Repository.cs:line 52
   at Orchard.Alias.Implementation.Storage.AliasStorage.Set(String path, IDictionary`2 routeValues, String source)
   at Orchard.Alias.Implementation.DefaultAliasService.Set(String aliasPath, RouteValueDictionary routeValues, String aliasSource)
   at Orchard.Alias.Implementation.DefaultAliasService.Replace(String aliasPath, RouteValueDictionary routeValues, String aliasSource)
   at Orchard.Autoroute.Services.AutorouteService.PublishAlias(AutoroutePart part)
   at Orchard.Autoroute.Handlers.AutoroutePartHandler.PublishAlias(AutoroutePart part)
   at Orchard.Autoroute.Handlers.AutoroutePartHandler.<.ctor>b__2(PublishContentContext ctx, AutoroutePart part)
   at Orchard.ContentManagement.Handlers.ContentHandler.InlineStorageFilter`1.Published(PublishContentContext context, TPart instance) in C:\Users\John\Source\Repo\src\Orchard\ContentManagement\Handlers\ContentHandler.cs:line 156
   at Orchard.ContentManagement.Handlers.StorageFilterBase`1.Orchard.ContentManagement.Handlers.IContentStorageFilter.Published(PublishContentContext context) in C:\Users\John\Source\Repo\src\Orchard\ContentManagement\Handlers\StorageFilterBase.cs:line 81
   at Orchard.ContentManagement.Handlers.ContentHandler.Orchard.ContentManagement.Handlers.IContentHandler.Published(PublishContentContext context) in C:\Users\John\Source\Repo\src\Orchard\ContentManagement\Handlers\ContentHandler.cs:line 274
   at Orchard.ContentManagement.DefaultContentManager.<>c__DisplayClass3f.b__3d(IContentHandler handler) in C:\Users\John\Source\Repo\src\Orchard\ContentManagement\DefaultContentManager.cs:line 351
   at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable`1 events, Action`1 dispatch, ILogger logger) in C:\Users\John\Source\Repo\src\Orchard\InvokeExtensions.cs:line 17
2012-09-12 17:35:16,103 [7] NHibernate.AdoNet.AbstractBatcher - Could not execute command: UPDATE Core_Portfolios_PortfolioRecord SET XmlConfig = @p0, Parameters = @p1 WHERE Id = @p2
System.InvalidOperationException: @p0 : String truncation: max=4000, len=8949, value='<!--?xml version="1.0" encoding="UTF-8"?-->



'.
   at System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(Boolean verifyValue)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
2012-09-12 17:35:16,288 [7] NHibernate.Impl.AbstractSessionImpl - DTC transaction prepre phase failed
System.InvalidOperationException: @p0 : String truncation: max=4000, len=8949, value='<!--?xml version="1.0" encoding="UTF-8"?-->


'.
   at System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(Boolean verifyValue)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
   at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session)
   at NHibernate.Action.EntityUpdateAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
   at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
   at NHibernate.Impl.SessionImpl.Flush()
   at NHibernate.Transaction.AdoNetWithDistrubtedTransactionFactory.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)

Sep 13, 2012 at 1:58 AM

BTW, I should note that I removed the majority of the XML just to keep the stack above small.

Sep 13, 2012 at 2:09 AM
corecomps wrote:

BTW, I should note that I removed the majority of the XML just to keep the stack above small.

Looks like the datatable is updated.

Image

Sep 13, 2012 at 5:56 AM

Don't forget the attribute that tells NHibernate not to truncate...

public class YourRecord : ContentPartRecord {
  [StringLengthMax]
   public virtual string YourLongString {get;set;}
}

Sep 14, 2012 at 3:14 AM
BrandonJoyce wrote:

Don't forget the attribute that tells NHibernate not to truncate...

 

public class YourRecord : ContentPartRecord {
  [StringLengthMax]
   public virtual string YourLongString {get;set;}
}

 

Of course that worked!  And just for good measure I looked a the BodyPart and sure enough!

Thanks to both of you for helping on this one.

 

    public class BodyPartRecord : ContentPartVersionRecord {
        [StringLengthMax]
        public virtual string Text { get; set; }

Lesson for the rest of us?  Make sure you not only set the length of the database column to support > 4000 but also make sure that the record field is also setup to allow NHibernate to store more than 4000!