A sample .NET 9 Web API for managing customers, products, tariffs, and orders for energy-based services (electricity, gas, etc.).
This project demonstrates a typical business structure for energy contract management:
Customer
└── Order
└── OrderDetail
├── Product
└── Tariff → Unit
Each tariff can have multiple time-based prices.
- .NET 9 / ASP.NET Core Web API
- Entity Framework Core
- SQL Server (default)
- Swagger / OpenAPI enabled by default
| Folder | Description |
|---|---|
Models/ |
Entity classes (Customer, Product, Tariff, Unit, Order, OrderItem) |
Data/ |
AppDbContext and SeedData for initialization |
Controllers/ |
API endpoints (to be extended) |
Migrations/ |
EF Core migrations |
Edit your appsettings.json to set the connection string:
"ConnectionStrings": {
"DefaultConnection": "xxx"
}On first startup, the app automatically seeds demo data.
To reseed the database (for development only), use:
SeedData.Initialize(db, force: true);This clears all tables and re-inserts demo data.
Generate a new migration whenever you modify the model classes:
dotnet ef migrations add AddNewFieldName
dotnet ef database updateCreated by Mahi © 2025