Problem:contentmanager connot create contentType

Topics: Customizing Orchard, Writing modules, 中文(Chinese)
Aug 3, 2014 at 10:28 AM
I have a problem :

NHibernate.Exceptions.GenericADOException: could not insert: [Physics.Question.Models.QuestionPartRecord#28][SQL: INSERT INTO Physics_Question_QuestionPartRecord (Question, Answer, Detial, Id) VALUES (?, ?, ?, ?)] ---> System.Data.SqlServerCe.SqlCeException: 在转换数据类型时数据被截断。 [ Name of function(if known) = ]
在 System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)

the fact is:
            ContentDefinitionManager.AlterTypeDefinition("Question",
    cfg => cfg
        .WithPart("QuestionPart")
        .WithPart("CommonPart", p => p
            .WithSetting("DateEditorSettings.ShowDateEditor", "true"))
        .WithPart("PublishLaterPart")
        .WithPart("AutoroutePart", builder => builder
            .WithSetting("AutorouteSettings.AllowCustomPattern", "true")
            .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
            .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Blog and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-blog/my-post'}]")
            .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
        .Draftable()
        .Creatable()
    );
                        var questionEntry = _contentManager.New<QuestionPart>("Question");

                        questionEntry.Answer = answer;
                        questionEntry.Question = question;
                        questionEntry.Detial = answerDetial;   
                        _contentManager.Create(questionEntry); 

                        _transactionManager.RequireNew();
I test many wayes, but eithor connot intert QuestionPartRecord or connot insert CommonPartRecord or AutoruatePartRecord , and I still test following way,eg:
                        dynamic questionEntry = _contentManager.New("Question");
                        _contentManager.Create(questionEntry); 
_transactionManager.RequireNew();
dynamic questionpart=questionEntry.QuestionPart;
                        questionpart.Answer = answer;
                        questionpart.Question = question;
                        questionpart.Detial = answerDetial;

                        
but connot update,the values of all are null;
who can help me? thank you, my english is poor, excuse me.
Developer
Aug 3, 2014 at 6:57 PM
Edited Aug 3, 2014 at 6:57 PM
Can you show us the migration code where you create the QuestionPartRecord table too, please?
Aug 4, 2014 at 5:36 AM
            SchemaBuilder.CreateTable("QuestionPartRecord", table => table
                .ContentPartRecord()
                .Column("Question", DbType.String)
                .Column("Answer", DbType.String)
                .Column("Detial", DbType.String)
            );
other,if i create Question Type in admin panel content ,it can run well.what's the matter?
Aug 4, 2014 at 6:23 AM
sfmskywalker wrote:
Can you show us the migration code where you create the QuestionPartRecord table too, please?
I know the problem was:
           SchemaBuilder.CreateTable("QuestionPartRecord", table => table
                .ContentPartRecord()
                .Column("Question", DbType.String)
                .Column("Answer", DbType.String)
                .Column("Detial", DbType.String)
            );
I had edit that as:
            SchemaBuilder.CreateTable("QuestionPartRecord", table => table
                .ContentPartRecord()
                .Column<string>("Question",x=>x.WithLength(5000))
                .Column<string>("Answer", x=>x.WithLength(5000))
                .Column<string>("Detial", x=>x.WithLength(5000))
            );
All runing ok.
Thank you!