Scaffolding for Records <-> Models?

Topics: Customizing Orchard, General, Writing modules
Jan 10, 2012 at 8:19 PM

Is there a way to auto generate the "Part" class from the "PartRecord" class? Or the other way around (though the former would be preferable)? 

And is there a way to scaffold the driver for a model, and editor templates too? 

Jan 12, 2012 at 1:47 AM

You could certainly write a T4 template to do this within Visual studio.. Then you can just right-click the Record and generate the Part file to save you some typing.

Please note that the two are different for a reason. They do not always have to match the same fields.
Your Part can include things not directly on the Record.


Jan 12, 2012 at 2:13 AM

There's also Piotr's module:

It will generate everything: part, record, driver, the lot.

Jan 12, 2012 at 3:20 AM

One of the things I've found annoying is having to map properties between objects and iterate through properties in multiple places. I just had to rename one property with a typo and did a find replace all -- 18 instances of the property name replaced!

Jan 12, 2012 at 3:20 AM

I'll take a look at Piotr's module. Thanks!

Jan 12, 2012 at 5:11 AM

Cool -- he has a blog post with more info about his scaffolding module: . 

Small Problem (& Fix):

My part has a lot of properties and the command to scaffold it is apparently too long for orchard.exe to read in. It won't process commands longer than 255 chars (due to a default of System.Console.In). It's an easy fix, but unfortunately I don't have time to learn Mercurial enough to submit code to Orchard at the moment. If anyone else has the time and know how to do this, would you mind submitting simple fix? Once my work project is not as busy I will be submitting some stuff on my own. 

Replace the contents of src/Tools/Orchard/Program.cs with the following:

using System;
using System.IO; 

namespace Orchard {
    public class Program {
        const int CONSOLE_INPUT_BUFFER_SIZE = 8192;

        public static int Main(string[] args) {
            Console.SetIn(new StreamReader(Console.OpenStandardInput(CONSOLE_INPUT_BUFFER_SIZE)));
            return (int)new OrchardHost(Console.In, Console.Out, args).Run();

Jan 12, 2012 at 12:14 PM

Raise a workitem for it, then someone will probably patch it since you provided the fix :)

Jan 12, 2012 at 12:15 PM

By the way, you can also run commands using the Web Command Line feature, it probably doesn't have the same limitation.

Jan 12, 2012 at 12:27 PM

Thanks for the tip. Work item created: