EffectiveTask/DeliveryWebApi/Model/DeliveryContext.cs
2024-10-29 23:38:02 +03:00

18 lines
No EOL
536 B
C#

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();
}
}