This project is read-only.

Why are we (still) writing our SchemaBuilder.CreateTable statements by hand?

Topics: Core, General, Writing modules
Feb 5, 2014 at 4:49 PM
After messing up a letter in a column name for a new record table, I was wondering why in the world I need to spell out the mapping of record properties to table columns by hand.

Take this example:
    table => table.ContentPartRecord()
                .Column<string>("Description", col => col.WithLength(4000))
                .Column<string>("CancellationTerms", col => col.WithLength(1000))
My record looks like this:
public class ProductPartRecord : ContentPartRecord {
    public virtual string ProductName { get; set; }
    public virtual string Description { get; set; }
    public virtual string CancellationTerms { get; set; }
    public virtual int ValidityPeriod { get; set; }
    public virtual decimal Price { get; set; }
There's nothing here that couldn't be easily automated. I understand that for advanced scenarios one might want/have to adjust the mapping here and there but in most situations I could imagine using something like the following should be all that's needed:
What do you think?
Feb 5, 2014 at 6:33 PM
Agreed, it would be awesome, if there was a GUI that will generate the models and migrations files for our custom content type modules. It wouldn't be a complicated build.
Feb 6, 2014 at 8:29 PM
It used to be automatic, before we had migrations. This needs to be explicit, it was a very deliberate decision. There are code gen options out there however that can help.
Feb 7, 2014 at 6:50 AM
Thanks Bertrand, I am not aware of the code gen options, can you please point us to the options available?
Feb 7, 2014 at 11:49 AM
See: We could have helpers for the SchemaBuilder to make such method calls strongly-types (somehow like AddColumn(record => record.MyProperty)). However we have to keep in mind that e.g. simply renaming the property won't rename it in the DB too... So still there is a migration step required.
Feb 7, 2014 at 12:46 PM
It would've been great if you can setup the content type in admin and you run a command line utility to reverse engineer it into a schema and migration file, so you can reuse the content type across different projects. Just an idea.
Feb 7, 2014 at 12:59 PM
Well you can export then import is, so you don't even have to write code.
Feb 7, 2014 at 2:16 PM
I guess thats right, only bad thing is that you don't have the luxury of a typed part, which is nice sometimes.