This project is read-only.

Custom content part problem.

Topics: Troubleshooting, Writing modules
Apr 25, 2013 at 9:28 PM
Edited Apr 25, 2013 at 9:29 PM
Hello. I've created custom content part basing on the following tutorial from github. I've done everything almost the same (I've added three string properties more). Next, I've created new Content Type that consists of my custom content part. The problem is that I can't create Content Item from definied Content Type. Orchard is throwing exception that transaction was aborted. The body of message contains message "Couldn't insert values". Data migration was created with tool, so I don't think it could be wrong. I've noticed, that SQL query contains values as ?,?,? - I have no idea why it happens. What's more, I've tried to create exactly the same code as in the tutorial, but the same result.

Any ideas?
Apr 25, 2013 at 9:38 PM
Looks like your migration is not right. It would help to share it.
Apr 25, 2013 at 9:59 PM
Module name is "MyModule.Module1"
Code generated by codegen:
public int Create()
        table =>
             .Column("CreateDate", DbType.String)
             .Column("LastDate", DbType.String)
             .Column("Description", DbType.String));

    ContentDefinitionManager.AlterPartDefinition("MyCustomPart", builder => builder.Attachable());

    return 1;
Apr 25, 2013 at 10:03 PM
That looks ok. Can you give the full error message?
Apr 25, 2013 at 10:04 PM
Your table name seems suspicious. Don't name your tables fully qualified with the namespace (unless this table name is the same name as your class).
E.g. if your class is named "MyCustomerPartRecord", create a equally-named table: "MyCustomerPartRecord", Orchard will take care of prefixing your module name.
Apr 25, 2013 at 10:06 PM
Good catch.
Apr 25, 2013 at 10:11 PM
I've thought that if I use codegen command, data migration would be proper (including table name). Here is full exception message:
could not insert: [MyModule.Module1.Models.MyCustomPartRecord#20][SQL: INSERT INTO MyModule_Module1_MyCustomPartRecord (CreateDate, LastDate, Description, Id) VALUES (?, ?, ?, ?)]
Apr 25, 2013 at 10:14 PM
You would be right to expect that. Alas, you may have found a bug. Would you mind reporting it as a bug via Issue Tracker?
Apr 25, 2013 at 10:17 PM
OTOH, the generated SQL seems to be using the correct table name. To be sure, I'd update your migration, wipe your database (assuming it's test only), and try again.
Apr 25, 2013 at 10:24 PM
Ok, so I'll try to use "MyCustomPart" as table name and I'll give you result in a few minutes.
Apr 25, 2013 at 10:36 PM
Ok - here is the result: after changing the table name everything... works fine! It seems that codegen creates a wrong table name.
Apr 26, 2013 at 12:39 PM
Glad to hear it. Would you mind filing a bug? Thanks!
Apr 26, 2013 at 3:17 PM
No, I don't :)
I've created work item.