Add New EF Core Entity With Spiderly
The EF Core entity and its attributes form the foundation of everything in
Spiderly. All other components are built and generated based on these
entities.
In this step-by-step guide, you'll learn how to create a new entity in your project. This includes adding it to the backend, updating the database, and generating the corresponding frontend code.
In this step-by-step guide, you'll learn how to create a new entity in your project. This includes adding it to the backend, updating the database, and generating the corresponding frontend code.
1. Open the Backend
Open the backend project located at your-app-name\Backend\YourAppName.sln using Visual Studio.
2. Add New Entity
In the backend project opened with Visual Studio, locate the YourAppName.Business\Entities
folder and add a new public class for your entity (e.g., YourEntityName.cs).
The entity class must inherit from BusinessObject<ID> if it supports create, read, update and delete operations, or from ReadonlyObject<ID> if it is read-only and does not support create, update, or delete operations from the UI.
The entity class must inherit from BusinessObject<ID> if it supports create, read, update and delete operations, or from ReadonlyObject<ID> if it is read-only and does not support create, update, or delete operations from the UI.
3. Add Your Entity to the Database
In the backend project opened with Visual Studio:
- Open Package Manager Console via View → Other Windows → Package Manager Console (or press Ctrl + `).
- Inside opened Package Manager Console window set YourAppName.Infrastructure as the Default Project in the dropdown.
- Run the command to create a migration:
- Run the command to apply the migration to the database:
4. Generate Components
Use the Spiderly CLI to generate a default template for your new entity. You can customize the generated files afterwards.
Run the following command from the root of your application:
Run the following command from the root of your application:
This will generate the following files:
-
API Controller - Located in your backend project opened with Visual Studio:
YourAppName.WebAPI\Controllers\YourEntityNameController.cs -
Details Page - In your Angular project (opened with Visual Studio Code):
src\app\pages\your-entity-name\your-entity-name-details.component.ts
src\app\pages\your-entity-name\your-entity-name-details.component.html -
List Page - Also in your Angular project:
src\app\pages\your-entity-name\your-entity-name-table.component.ts
src\app\pages\your-entity-name\your-entity-name-table.component.html
5. Define Routes for Your Page
In the frontend project opened with Visual Studio Code, locate the src\app\app.routes.ts file
and add new child routes under the layout component's children array: