Create custom ID

Topics: Writing modules
Mar 20, 2013 at 1:37 PM
How do I create a ContentPart with an ID of type STRING and not an INT?

PS: Sorry for my bad english (I used google translator) :(
Developer
Mar 20, 2013 at 1:49 PM
Edited Mar 20, 2013 at 1:50 PM
You can't; The ID of the content part records is used to link these records with the content item they are part of, whose ID's are all ints. You would have to refactor Orchard to have strings as IDs. Why do you want to use a string for the ID?
Coordinator
Mar 20, 2013 at 6:02 PM
"How do I create a ContentPart with an ID of type STRING and not an INT? "

You don't want to do it.
And if you need a LOGICAL id, then add it to your own records.
Mar 20, 2013 at 6:22 PM
You could also attach an IdentityPart to your content type, and pull the Identifier value, which is a unique string. The ID will be generated for you.
Mar 21, 2013 at 10:39 AM
Edited Mar 21, 2013 at 10:41 AM
Thank you all for the answers.
I have these tables:

Course
SchemaBuilder.CreateTable(
    "CoursePartRecord",
    table => table
        .ContentPartRecord()
        .Column("Title", DbType.String, c => c.WithLength(200).NotNull())
        .Column("TypeId", DbType.String, c => c.WithLength(20).NotNull())
        .Column("StartDate", DbType.DateTime)
        .Column("EndDate", DbType.DateTime)
        .Column("Location", DbType.String, c => c.WithLength(200))
        .Column("Note", DbType.String, c => c.Unlimited()));

SchemaBuilder.CreateForeignKey("Course_Type", "CoursePartRecord", new[] { "TypeId" }, "TypePartRecord", new[] { "Id" });
Type
SchemaBuilder.CreateTable(
    "TypePartRecord",
    table => table
        .Column("Id", DbType.String, c => c.WithLength(20).NotNull().Unique())
        .Column("Description", DbType.String, c => c.WithLength(100).NotNull()));
The field TypeId is a ForeignKey with the Id of the table Type, but so I can not use ContentPart
I solved this way:

Course
SchemaBuilder.CreateTable(
    "CoursePartRecord",
    table => table
        .ContentPartRecord()
        .Column("Title", DbType.String, c => c.WithLength(200).NotNull())
        .Column("Type", DbType.String, c => c.WithLength(20).NotNull())
        .Column("StartDate", DbType.DateTime)
        .Column("EndDate", DbType.DateTime)
        .Column("Location", DbType.String, c => c.WithLength(200))
        .Column("Note", DbType.String, c => c.Unlimited()));

SchemaBuilder.CreateForeignKey("Course_Type", "CoursePartRecord", new[] { "Type" }, "TypePartRecord", new[] { "Code" });
Type
SchemaBuilder.CreateTable(
    "TypePartRecord",
    table => table
        .ContentPartRecord()
        .Column("Code", DbType.String, c => c.WithLength(20).NotNull().Unique())
        .Column("Description", DbType.String, c => c.WithLength(100).NotNull()));