-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyDbContext.cs
30 lines (26 loc) · 861 Bytes
/
MyDbContext.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
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Repro;
public class MyDbContext(SqliteConnection sqliteConnection) : DbContext
{
public DbSet<One> Ones { get; set; } = null!;
public DbSet<Two> Twos { get; set; } = null!;
public DbSet<OneTwo> OneTwos { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlite(sqliteConnection);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<One>()
.HasMany(o => o.Twos)
.WithMany(t => t.Ones)
.UsingEntity<OneTwo>(
j =>
{
j.Property(o => o.Order).HasDefaultValue(0);
});
}
}