Data model. Introduction

Describe your data model to allow DWKit to work with your database. Each data model entity refers to a table in the database. Data model also includes attributes which correlate to table columns in the database. In this section you will learn how to create Data Model and synchronize it with database, which attributes (columns) you can create and how they work. We'll also talk about primary keys selection.

Tutorial

Data Model and database synchronization in DWKit

Very often, when you have just started creating a new system, you already have partially or fully-built database. In the Sync With Database section in the admin panel you can synchronize your database with your Data Models. DWKit will request to analyze database structure and will specify discrepancies between your database and Data Models. After which you'll be able to apply this difference to all Data Models in the system or to a particular attribute of a certain Data Model. In this way, DWKit adheres to designing the data structure when the database is primary. First you make changes to your database and then transfer these changes to DWKit. We do not provide reverse synchronization (transfer of changes from DWKit into the database) for the following reasons:

  • When you create tables in database with SQL scripts, you are using database full potential. For example, you can create indexes and customize cascade delete. DWKit does not need most of these settings to load and save data. Full database management UI implementation would definitely result in multiple compatibility problems and would make DWKit admin panel UI too complicated.
  • It is not recommended to give applications admin access to database. This access is required to change data structure in database.
  • When changing data structure, you often need to perform some additional operations. For example, backup data and run additional scripts. It means that we would have complicated data structure manipulations, instead of simplifying them, as all changes would have to be made in two separate places. Thus, DWKit always projects data structure from the database.

Data Model editing in DWKit

Any DWKit-based system developer (or advance user) usually edits Data Models in the Manage data model section of the admin panel. See UI example here. This interface describes which table in database Data Model and all its attributes (columns) are bound to.

Storing Data Models in DWKit

DWKit stores JSON serialized Data Models in the file system. By default, Data Models are stored in the Metadata folder in the metadata.json file of ASP.NET MVC Core DWKit project. In all our examples and starter packs this project is called OptimaJet.DWKit.StarterApplication. Thus you can use your favorite VCS (for example, git) for joint development and data models version control.