EffectiveTask/DeliveryWebApi/Model/DeliveryContext.cs

18 lines
536 B
C#
Raw Normal View History

2024-10-29 20:38:02 +00:00
using Microsoft.EntityFrameworkCore;
namespace DeliveryWebApi.Model;
public class DeliveryContext(DbContextOptions<DeliveryContext> options) : DbContext(options)
{
public DbSet<District> Districts { get; init; }
public DbSet<Order> Orders { get; init; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<District>()
.HasMany(e => e.Orders)
.WithOne(e => e.District)
.HasForeignKey(e => e.DistrictId)
.IsRequired();
}
}