Created
November 25, 2020 02:07
-
-
Save Patrick-Ullrich/aee278201c269e09f57e2bb0ae71de71 to your computer and use it in GitHub Desktop.
DbContext w/ M2M
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StreamingContext : DbContext | |
{ | |
public StreamingContext(DbContextOptions<StreamingContext> options) : base(options) { } | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.Entity<Streamer>() | |
.HasMany(s => s.Subscribers) | |
.WithMany(s => s.Streamers) | |
.UsingEntity<Subscription>( | |
j => j.HasOne(s => s.Subscriber).WithMany(s => s.Subscriptions), | |
j => j.HasOne(s => s.Streamer).WithMany(s => s.Subscriptions)); | |
} | |
public DbSet<Streamer> Streamers { get; set; } | |
public DbSet<Subscriber> Subscribers { get; set; } | |
public DbSet<Subscription> Subscriptions { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment