Adding a Movie Kind Field

    As we didn’t add it while creating the Movie table, now we’ll write another migration to add it to our database.

    Create another migration file under Modules/Common/Migrations/DefaultDB/ DefaultDB_20160519_145500_MovieKind.cs:

    Now as we added Kind column to Movie table, we need a set of movie kind values. Let’s define it as an enumeration at MovieTutorial.Web/Modules/MovieDB/Movie/MovieKind.cs:

    1. using System.ComponentModel;
    2. namespace MovieTutorial.MovieDB
    3. {
    4. public enum MovieKind
    5. {
    6. [Description("Film")]
    7. [Description("TV Series")]
    8. TvSeries = 2,
    9. [Description("Mini Series")]
    10. MiniSeries = 3
    11. }
    12. }

    Adding Kind Field to MovieRow Entity

    As we are not using Sergen anymore, we need to add a mapping in our MovieRow.cs for Kind column manually. Add following property declaration in MovieRow.cs after Runtime property:

    We also need to declare a Int32Field object which is required for Serenity entity system. On the bottom of MovieRow.cs locate RowFields class and modify it to add Kind field after the Runtime field:

    1. public class RowFields : RowFieldsBase
    2. public readonly Int32Field Runtime;
    3. public readonly Int32Field Kind;
    4. public RowFields()
    5. : base("[mov].Movie")
    6. {
    7. LocalTextPrefix = "MovieDB.Movie";
    8. }

    Modify MovieForm.cs as below:

    Now, build your solution and run it. When you try to edit a movie or add a new one, nothing will happen. This is an expected situation. If you check developer tools console of your browser (F12, inspect element etc.) you’ll see such an error:

    1. Uncaught Can't find MovieTutorial.MovieDB.MovieKind enum type!

    Please Note!

    Whenever such a thing happens, e.g. some button not working, you got an empty page, grid etc, please first check browser console for errors, before reporting it.

    This error is caused by MoveKind enumeration not available client side. We should run our T4 templates before executing our program.

    Now in Visual Studio, click Build -> Transform All Templates again.

    Declaring a Default Value for Movie Kind

    As Kind is a required field, we need to fill it in Add Movie dialog, otherwise we’ll get a validation error.

    But most movies we’ll store are feature films, so its default should be this value.

    To add a default value for Kind property, add a DefaultValue attribute like this:

    Now, in Add Movie dialog, Kind field will come prefilled as Film.