estatedocflow / estatedocflow.api

0 stars 0 forks source link

Install PostgreSQL with Docker and Integrate with EF Core #17

Open estatedocflow opened 1 month ago

estatedocflow commented 1 month ago

Description

Set up a PostgreSQL database using Docker containers and integrate it with Entity Framework Core (EF Core).

Requirements

  1. Docker Compose Configuration:
version: '3.8'
services:
  postgres:
    image: postgres
    environment:
      POSTGRES_DB: "real_estate_db"
      POSTGRES_USER: "username"
      POSTGRES_PASSWORD: "password"
    ports:
      - "5432:5432"
  1. Entity Framework Core Integration:

Configure EF Core to connect to the PostgreSQL database using the Npgsql provider.

// DbContext class for PostgreSQL
public class RealEstateDbContext : DbContext
{
    public RealEstateDbContext(DbContextOptions<RealEstateDbContext> options) : base(options)
    {
    }

    public DbSet<Booking> Bookings { get; set; }
    public DbSet<Customer> Customers { get; set; }
    // Define other DbSet properties for database entities
}
  1. Connection String Configuration:

Define the connection string in appsettings.json and appsettingsdev.json to connect to the PostgreSQL database.

{
  "ConnectionStrings": {
    "RealEstateDbConnection": "Server=localhost;Port=5432;Database=real_estate_db;User Id=username;Password=password;"
  }
}
estatedocflow commented 1 month ago

@Riya2993 sign here working hours, please!

You missed also the PR to merge it in the dev branch, please added it.

estatedocflow commented 1 month ago

Use Markdown for the documentation, in this moment it is unformatted.