-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoContext.cs
34 lines (29 loc) · 961 Bytes
/
DemoContext.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
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace ConsoleApplication
{
public class DemoContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=DemoRepro;Trusted_Connection=true;")
.ConfigureWarnings(wc => wc.Throw(RelationalEventId.QueryClientEvaluationWarning));
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<MainEntity>()
.HasOne(m => m.Child).WithMany().IsRequired(false);
}
}
public class MainEntity
{
public int Id { get; set; }
public ChildEntity Child { get; set; }
}
public class ChildEntity
{
public int Id { get; set; }
public string Text { get; set; }
}
}