Skip to content
Snippets Groups Projects
ApplicationDbContext.cs 721 B
Newer Older
using Microsoft.EntityFrameworkCore;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace FlightMicroservice.Models
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

        public DbSet<Flight> Flights { get; set; }
        public DbSet<Seat> Seats { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Seat>()
                .HasOne(seat => seat.Flight)
                .WithMany(flight => flight.Seats)
                .HasForeignKey(seat => seat.FlightId);
        }
    }
}