Generating an Entity Domain Model

Generating an entity domain model is similar to generating a business model. The generation process is two step:

  • Generate json from entityDomainModel.template
  • Generate the Entity Framework Core entity types, corresponding DBSets, and corresponding meta classes

The Entity Domain Model we are referring to here is not a database-centric but moreso a Unified Modeling Language (UML) structure. Since it is used to generate classes, it really drives a Entity Framework "code first" Domain Driven design. Although the model is truly language-agnostic, it maps closely to the C# data types you are familiar with.

Hydra also comes with a starter entity domain model template. The default template is located here: C:\Program Files (x86)\CloudIDEaaS\Hydra\GeneratorTemplates\Default\entityDomainModel.template

Step 1: Generate entities from template and business model

Prior to generating entities from a template, you must also have an existing business model json file. The entities are linked to the data items in the business model. To generate a entities from a template, run the following:

hydra generate entities --template <templatename> --businessmodel <businessmodel json file>

For example:

hydra generate entities --template "C:\Program Files (x86)\CloudIDEaaS\Hydra\GeneratorTemplates\Default\entityDomainModel.template" --businessmodel businessModel.json

The command assumes the businessModel.json is in the current directory from where running the command. You can also provide a full path. A shortcut for using the default template file:

hydra generate entities --template default

This command syntax version assumes the businessModel.json in the current directory named as such. You can also simply run:

hydra generate entities

Like the business model template, you can also provide your own template and use the first example, passing in the path. Again, the above commands do nothing more than convert a flat file (tab delimited) to an equivalent JSON file that is more easily read by further generator commands. Below are examples of the businessModel.template and the resulting json file:

entityDomainModel.template

Resulting entities.json

{
  "entities": [
    {
      "name""User",
      "parentDataItem": 7,
      "isInherentDataItem"false,
      "attributes": [
        {
          "attributeType""string",
          "name""First Name",
          "properties": [
            {
              "propertyName""IdentityField",
              "childProperties": [
                {
                  "propertyName""UIHierarchyPath",
                  "propertyValue""*"
                },
                {
                  "propertyName""IdentityFieldKind",
                  "propertyValue""Client"
                }
              ]
            },
            {
              "propertyName""DisplayName",
              "propertyValue""First Name"
            }
          ]
        },
        {
          "attributeType""string",
          "name""Last Name",
          "properties": [
            {
              "propertyName""IdentityField",
              "childProperties": [
                {
                  "propertyName""UIHierarchyPath",
                  "propertyValue""*"
                },
                {
                  "propertyName""IdentityFieldKind",
                  "propertyValue""Client"
                }
              ]
            },
            {
              "propertyName""DisplayName",
              "propertyValue""Last Name"
            }
          ]
        },
        {
          "attributeType""string",
          "name""User Name",
          "properties": [
            {
              "propertyName""IdentityField",
              "childProperties": [
                {
                  "propertyName""UIHierarchyPath",
                  "propertyValue""*"
                },
                {
                  "propertyName""IdentityFieldKind",
                  "propertyValue""UserName"
                }
              ]
            },
            {
              "propertyName""DisplayName",
              "propertyValue""User Name"
            },
            {
              "propertyName""MinLength",
              "propertyValue""8"
            },
            {
              "propertyName""MaxLength",
              "propertyValue""50"
            }
          ]
        },
        {
          "attributeType""string",
          "name""Email Address",
          "properties": [
            {
              "propertyName""DataType",
              "childProperties": [
                {
                  "propertyName""DataType",
                  "propertyValue""EmailAddress"
                }
              ]
            },
            {
              "propertyName""IdentityField",
              "childProperties": [
                {
                  "propertyName""UIHierarchyPath",
                  "propertyValue""*"
                },
                {
                  "propertyName""IdentityFieldKind",
                  "propertyValue""Client"
                }
              ]
            },
            {
              "propertyName""DisplayName",
              "propertyValue""Email Address"
            }
          ]
        },
        {
          "attributeType""string",
          "name""Password Hash",
          "properties": [
            {
              "propertyName""IdentityField",
              "childProperties": [
                {
                  "propertyName""UIHierarchyPath",
                  "propertyValue""*"
                },
                {
                  "propertyName""IdentityFieldKind",
                  "propertyValue""PasswordHash"
                }
              ]
            },
            {
              "propertyName""DisplayName",
              "propertyValue""Password"
            },
            {
              "propertyName""MinLength",
              "propertyValue""8"
            },
            {
              "propertyName""MaxLength",
              "propertyValue""50"
            }
          ]
        },
        {
          "attributeType""bool",
          "name""Enabled",
          "properties": []
        },
        {
          "attributeType""related entity",
          "name""Role",
          "properties": [
            {
              "propertyName""RelatedEntity",
              "childProperties": [
                {
                  "propertyName""RelationshipKind",
                  "propertyValue""ContainsManyToMany",
                  "childProperties": [
                    {
                      "propertyName""ExistingEntity",
                      "propertyValue""Role"
                    },
                    {
                      "propertyName""LookupOfAnotherEntity",
                      "propertyValue""TRUE"
                    },
                    {
                      "propertyName""ContainerName",
                      "propertyValue""User Roles"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "properties": [
        {
          "propertyName""IdentityEntity",
          "childProperties": [
            {
              "propertyName""IdentityEntityKind",
              "propertyValue""User"
            }
          ]
        },
        {
          "propertyName""UIGroup",
          "childProperties": [
            {
              "propertyName""UINavigationName",
              "childProperties": [
                {
                  "propertyName""Name",
                  "propertyValue""Login"
                }
              ]
            },
            {
              "propertyName""UI",
              "childProperties": [
                {
                  "propertyName""UIHierarchPath",
                  "propertyValue""Login"
                },
                {
                  "propertyName""UIKind",
                  "propertyValue""LoginPage"
                }
              ]
            }
          ]
        },
        {
          "propertyName""Authorize",
          "childProperties": [
            {
              "propertyName""AuthorizationState",
              "propertyValue""SkipAuthorization"
            }
          ]
        }
      ]
    },
    {
      "name""Role",
      "parentDataItem": 0,
      "isInherentDataItem"true,
      "attributes": [
        {
          "attributeType""string",
          "name""Name",
          "properties": [
            {
              "propertyName""IdentityField",
              "childProperties": [
                {
                  "propertyName""UIHierarchyPath",
                  "propertyValue""*"
                },
                {
                  "propertyName""IdentityFieldKind",
                  "propertyValue""RoleName"
                }
              ]
            }
          ]
        },
        {
          "attributeType""bool",
          "name""Is Admin Role",
          "properties": [
            {
              "propertyName""IdentityField",
              "childProperties": [
                {
                  "propertyName""UIHierarchyPath",
                  "propertyValue""*"
                },
                {
                  "propertyName""IdentityFieldKind",
                  "propertyValue""IsAdminRole"
                }
              ]
            }
          ]
        }
      ],
      "properties": [
        {
          "propertyName""IdentityEntity",
          "childProperties": [
            {
              "propertyName""IdentityEntityKind",
              "propertyValue""Role"
            }
          ]
        }
      ]
    }
  ]
}

Step 2: Generate entity types, DBSets, and meta classes from json file

This step is where the real magic begins, generating real c# code. To generate a entities from a json file, run the following:

hydra generate entities --fromjson <entities json file> --businessmodel <businessmodel json file>

For example:

hydra generate entities --fromjson entities.json --businessmodel businessModel.json

The command assumes the businessModel.json and entities.json is in the current directory from where running the command. You can also provide a full path for either. A shortcut for the described case is as follows:

hydra generate entities --fromjson

Resulting C# example


© CloudIDEaaS, 1996-2022 • Updated: 10/03/20
Comment or report problem with topic