Unable to use ntext / clob columns

Topics: Customizing Orchard, Troubleshooting, Writing modules
Apr 6, 2011 at 10:41 PM

I have a table created in the sql ce database for my content part "CourseDescription". The "Syllabus" column uses ntext as it's type. However, when I try to create a CourseDescription I get the following exception:

[InvalidOperationException: @p1 : String truncation: max=4000, len=11501, value='<p>
<strong>About this Course</strong><br />

  System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(Boolean verifyValue) +914
   System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options) +614
   System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery() +21
   NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) +297
   NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation) +16
   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) +968
   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) +195
   NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session) +354
   NHibernate.Action.EntityUpdateAction.Execute() +399
   NHibernate.Engine.ActionQueue.Execute(IExecutable executable) +117
   NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +92
   NHibernate.Engine.ActionQueue.ExecuteActions() +27
   NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +121
   NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +56
   NHibernate.Impl.SessionImpl.Flush() +292
   NHibernate.Transaction.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment) +395

[TransactionAbortedException: The transaction has aborted.]
   System.Transactions.TransactionStateAborted.EndCommit(InternalTransaction tx) +11
   System.Transactions.CommittableTransaction.Commit() +239
   System.Transactions.TransactionScope.InternalDispose() +402
   System.Transactions.TransactionScope.Dispose() +1450
   Orchard.Data.TransactionManager.System.IDisposable.Dispose() in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Data\TransactionManager.cs:43
   Autofac.Core.Disposer.Dispose(Boolean disposing) +79
   Autofac.Util.Disposable.Dispose() +46
   Autofac.Core.Lifetime.LifetimeScope.Dispose(Boolean disposing) +21
   Autofac.Util.Disposable.Dispose() +46
   Orchard.Environment.<>c__DisplayClass2.<.ctor>b__0() in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Environment\WorkContextAccessor.cs:75
   Orchard.Environment.HttpContextScopeImplementation.System.IDisposable.Dispose() in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Environment\WorkContextAccessor.cs:80
   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Mvc\Routes\ShellRoute.cs:158
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

How can I get around this?

 

 

Coordinator
Apr 6, 2011 at 11:11 PM

Can you show your migration?

Apr 7, 2011 at 1:12 AM
Edited Apr 7, 2011 at 1:12 AM

 

 

 public class Migrations : DataMigrationImpl {
        public int Create() {            
            SchemaBuilder.CreateTable("CourseDescriptionRecord", table => table
                .ContentPartRecord()
                .Column("CourseNumber", DbType.String)
                .Column("Syllabus", DbType.String, c => c.Unlimited())
            );

            ContentDefinitionManager.AlterPartDefinition(typeof(CourseDescriptionPart).Name, cfg => cfg
                .Attachable());

            ContentDefinitionManager.AlterTypeDefinition("CourseDescription", x => x.WithPart("CourseDescriptionPart")
                                                                                    .WithPart("CommonPart")
                                                                                    .WithPart("RoutePart")
                                                                                    .WithPart("TagsPart")
                                                                                    .Creatable()
                                                                                    .Indexed());

            

            return 1;
        }     
    }
Coordinator
Apr 7, 2011 at 1:29 AM

Have you set a StringLengthMax attribute in your record ?

[StringLengthMax]
public virtual string Text { get; set; }

This will tell NHibernate about the mapping also. If you don't do it, only the db is aware. 


Feb 7, 2012 at 11:15 PM

Yes this worked for me! Thanks!!