-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChecklistContext.cs
More file actions
28 lines (24 loc) · 840 Bytes
/
Copy pathChecklistContext.cs
File metadata and controls
28 lines (24 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using Microsoft.EntityFrameworkCore;
using Sample.Repository.Model;
namespace Sample.Repository
{
public class ChecklistContext : DbContext
{
public DbSet<Checklist>? Checklists { get; set; }
public DbSet<CheckItem>? CheckItems { get; set; }
public ChecklistContext(DbContextOptions<ChecklistContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Checklist>()
.HasKey(c => c.ID);
modelBuilder.Entity<CheckItem>()
.HasKey(ci => ci.ID);
modelBuilder.Entity<Checklist>()
.HasMany(c => c.CheckItems)
.WithOne(ci => ci.Checklist)
.HasForeignKey(ci => ci.ChecklistID);
}
}
}