Search This Blog

Generate Code from SERGEN (Serenity Code Generator)

After we have created tables in DataBase, we can use SERGEN to generate all the code to make a basic application running i.e. create-update-delete functionality for all those database objects.

Here, we already created a table with the following migration script.

using FluentMigrator;
using System;

namespace ERP.Migrations.DefaultDB
{
    [Migration(20200411033300)]
    public class Class : Migration
    {
        public override void Up()
        {
            this.CreateTableWithId32("Movie", "MovieId", s => s
            .WithColumn("Title").AsString(200).NotNullable()
            .WithColumn("Description").AsString(1000).Nullable()
            .WithColumn("Storyline").AsString(Int32.MaxValue).Nullable()
            .WithColumn("Year").AsInt32().Nullable()
            .WithColumn("ReleaseDate").AsDateTime().Nullable()
            .WithColumn("Runtime").AsInt32().Nullable());
        }
        public override void Down()
        {
        }
    }

}

Login to serenity Application using admin credentials


Now, in the left side navigation pane, goto Administration --> Sergen and select the connection from right pane.


Now select your table i.e Movie and module name i.e. MovieDataBase (Changed from default) in our case. And click the "Generate Code" button.

Now, we can see in solution explorer of visual stdio that SERGEN has generated some files 

We need to build and execute our project using Ctrl+Shift+B. Then after building the project, we get following errors,



To remove these errors, we replaced Stream, StreamField variable types with respective type. In our case these were String, DateTime, StringFeild and DateTimeField in files movieRow.cs, movieForm.cs and movieColumn.cs .

And we added partial keyword to remove the 3rd error.     
public partial class PermissionKeys

Now we will run the project by pressing Ctrl + F5, and after logging in the serenity application, we will navigate to MovieDataBase -->Movie and we can see that here we can add, delete and update data in movie table.



No comments:

Post a Comment

Web Statistics