Creating a DB Entity
DB Entities are used to define data that requires persistence. For each DB Entity created, a corresponding database table is generated.
Example: In an e-commerce application, entities such as Customer, Address, Order, OrderItems, and Product are defined as DB Entities since they need to be stored persistently.
Key Characteristics of a DB Entity
- Uniqueness – Each entity has a unique identifier, often called a Primary Key.
- Attributes – Entities have properties that describe them, known as fields or columns in a database table.
- Relationships – Entities can be linked to other entities through relationships (e.g., one-to-many, one-to-one, many-to-many).
- Persistence – For every DB Entity a relational table is created.
Add Folder
For better organization and accessibility, users can group database entities into folders.
- Create a Folder:
- Right-click DB Entities in the Explorer Menu.
- Select Add Folder and provide a name for the folder.
Creating a DB Entity
Steps to Create a DB Entity
-
Add a New Entity
- Open the Explorer menu.
- Right-click on DB Entities/Folder.
- Select Add Entity.
-
Configure Entity Properties
In the Properties Panel, set the required fields:
Property Description Comments Name* Name of the entity. Must start with an uppercase letter followed by alphanumeric characters or ''. No spaces or special characters except ''. Cannot start with a number. Maximum length: 50 characters. Specifies the table name in the database. Plural Name* Plural form of the entity name. Automatically generated based on the Name field. Plural name used to create API route URL for the default service actions. Suffix A DB entity suffix is an optional string appended to the table name. Values: Yes/No. Default: No. Is Binary Used to store files within a database table as described below. Values: Yes/No. Default: No. Is Active Indicates if the entity is active. Values: Yes/No. Default: Yes. Description Description of the entity. Optional. -
Save the Entity
- Click the Save icon.
- Upon successful creation, you should see the message: "DB Entity saved successfully".
Entity Suffix
A DB entity suffix is an optional string appended to the table name when creating an entity in a database. Suffix is used to distinguish or categorize tables without modifying the core entity name.
Purpose of a Suffix in a DB Entity
- Helps differentiate similar entities (e.g., User_Log vs. User_Details).
- Can indicate entity type, function, or versioning (e.g., _Archive, _Temp).
- Useful for naming conventions in large-scale applications.
Examples
| Entity Name | Suffix | Final Table Name |
|---|---|---|
| Order | _History | Order_History |
| User | _Details | User_Details |
| Transaction | _Archive | Transaction_Archive |
Binary Entity
A Binary Entity is a specialized type of DB Entity designed specifically for storing files within an application. Storing binary data (such as images, PDFs, or other files) in a dedicated table improves performance and maintainability by preventing frequent updates to regular entities, which can negatively impact database efficiency.
Scenario: Managing User Profiles with Profile Pictures
When designing an application that stores user profiles along with profile pictures, you can choose between:
- Storing profile pictures within the UserProfile table (not recommended).
- Separating profile pictures into a dedicated Binary Entity (ProfilePic) (recommended for better performance).
Why Separate ProfilePic into a Different Table?
- Performance Optimization – Frequent updates to user profiles (e.g., name, email, preferences) won't affect large binary data.
- Reduced Database Load – Queries on UserProfile remain fast since they don't load binary data.
- Better Scalability – Storing binary data separately allows using optimized storage solutions (e.g., cloud storage).
- Efficient Caching – Profile data can be cached efficiently without storing large image blobs.
Recommendation: Store large files in external storage (e.g., Blob Storage, S3) and maintain only a reference in the Entity.
Default Attributes of a Binary Entity
When a Binary Entity is created, it automatically includes the following attributes:
| Attribute | Description |
|---|---|
| Id (Primary Key) | Unique identifier for the binary entity record. |
| FileName | Name of the uploaded file. |
| BinaryData | The actual binary content of the file (stored in a BLOB field). |
| FileExtension | The file type extension (e.g., .png, .pdf). |
| FileSize | Size of the file in bytes. |
| ContentType | MIME type of the file (e.g., image/png, application/pdf). |
| URL | A reference or direct access URL. |
Additional attributes can be added based on the specific requirements.
Structure of a DB Entity
When a DB Entity is created, it consists of the following components:
-
ID Attribute (Primary Key)
- Automatically generated as the primary key.
- Ensures uniqueness for each record.
-
List of Attributes
- Represents the properties of the entity.
- Each attribute has a name, data type, and optional constraints (e.g., required, unique).
- Example attributes for a Customer entity:
- CustomerID (Primary Key)
- Name (String)
- Email (String, Unique)
- CreatedDate (DateTime)
-
Actions Folder (CRUD Operations)
Contains pre-built operations for managing entity data:
- Create – Adds a new record.
- Read – Retrieves existing records.
- Update – Modifies existing data.
- Delete – Removes a record from the database.
- Bulk Create or Update – Adds multiple records.
-
Indexes Folder
- Stores database indexes that improve query performance.
- Can be manually added for optimizing searches on frequently queried attributes.