-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeSliceContext.cs
36 lines (31 loc) · 1.49 KB
/
TimeSliceContext.cs
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
29
30
31
32
33
34
35
36
using ExampleClasses.Festival;
using Microsoft.EntityFrameworkCore;
using TimeSliceEntityFrameworkExtensions;
namespace ExampleWebApplication
{
/// <summary>
/// a database contexts that uses the <see cref="ExampleClasses" />
/// </summary>
public class TimeSliceContext : DbContext
{
public TimeSliceContext(DbContextOptions<TimeSliceContext> options) : base(options)
{
Database.EnsureCreated();
}
public DbSet<Musician> Musicians { get; set; }
public DbSet<Listener> Listeners { get; set; }
// two db sets using the same base type must not interfere
public DbSet<Concert> Concerts { get; set; }
public DbSet<BackstageMeetings> BackstageMeetings { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.SetupCollectionAndRelations<Concert, ConcertVisit, Musician, string, Listener, string>(
concert => concert.Guid // but keys for ConcertVisit can be derived automatically (null)
);
modelBuilder.SetupCollectionAndRelations<BackstageMeetings, OneOnOneWithAStar, Musician, string, Listener, string>(
backstageMeeting => backstageMeeting.Guid, // The key of a collection (BackstageMeetings) has to be explicitly set, always
oneOnOneWithAStar => oneOnOneWithAStar.MeetingGuid // it's possible to also explicitly set a key for the relation (!=null)
);
}
}
}