-
Notifications
You must be signed in to change notification settings - Fork 9
/
OrdersContext.cs
53 lines (43 loc) · 1.38 KB
/
OrdersContext.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
public class OrdersContext : DbContext
{
private readonly bool _log;
public OrdersContext()
{
}
public OrdersContext(bool log)
{
_log = log;
}
public DbSet<Customer> Customers { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Order> Orders { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Orders");
if (_log)
{
optionsBuilder
.EnableSensitiveDataLogging()
.LogTo(Console.WriteLine, new[] { RelationalEventId.CommandExecuted });
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<Product>()
.Property(e => e.Price)
.HasPrecision(18, 2);
modelBuilder
.Entity<Customer>()
.ToTable("Customers", b => b.IsTemporal());
modelBuilder
.Entity<Product>()
.ToTable("Products", b => b.IsTemporal());
modelBuilder
.Entity<Order>()
.ToTable("Orders", b => b.IsTemporal());
}
}