using DotnetToLambda.Core.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; namespace DotnetToLambda.Core.Infrastructure { public class BookingContext : DbContext { private readonly DatabaseConnection _connection; public BookingContext(DatabaseConnection connection) { this._connection = connection; } public DbSet Bookings { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseMySQL(this._connection.ToString()); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().ToTable("Bookings"); modelBuilder.Entity() .HasKey(b => b.BookingId).HasName("PK_BookingId"); modelBuilder.Entity() .HasIndex(b => b.CustomerId) .HasName("UX_Booking_CustomerId"); } } }