This project is a Minimal API built with ASP.NET Core that uses Entity Framework Core for data access and SQLite as the database. The API manages User
and Order
entities and includes basic CRUD operations.
- Minimal API structure using ASP.NET Core.
- Entity Framework Core for data access.
- SQLite as the database.
- CRUD operations for
User
andOrder
entities. - Swagger for API documentation and testing.
-
Clone the repository:
git clone https://github.com/yourusername/minimal-api-database.git cd minimal-api-database
-
Restore the dependencies:
dotnet restore
-
Apply migrations to create the database:
dotnet ef database update
-
Run the application:
dotnet run
Models
: Contains theUser
andOrder
entity classes.Data
: Contains theApplicationDbContext
class for EF Core.Migrations
: Contains the EF Core migration files.Program.cs
: Configures the services and middleware, and defines the endpoints.
- GET /users: Retrieve all users.
- GET /users/{id}: Retrieve a user by ID.
- POST /users: Create a new user.
- PUT /users/{id}: Update an existing user.
- DELETE /users/{id}: Delete a user by ID.
- GET /orders: Retrieve all orders.
- GET /orders/{id}: Retrieve an order by ID.
- POST /orders: Create a new order.
- PUT /orders/{id}: Update an existing order.
- DELETE /orders/{id}: Delete an order by ID.
Once the application is running, you can use Swagger to explore and test the API endpoints. Swagger will be available at:
The application uses SQLite for the database. The connection string is configured in Program.cs
:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlite($"Data Source={AppDomain.CurrentDomain.BaseDirectory}app.db");
});