18 lines
No EOL
536 B
C#
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();
|
|
}
|
|
} |