-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBoilerplateDbContext.cs
More file actions
47 lines (41 loc) · 1.23 KB
/
Copy pathBoilerplateDbContext.cs
File metadata and controls
47 lines (41 loc) · 1.23 KB
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
using BervProject.WebApi.Boilerplate.Entities;
using Microsoft.EntityFrameworkCore;
namespace BervProject.WebApi.Boilerplate.EntityFramework
{
/// <summary>
/// DB Context
/// </summary>
public class BoilerplateDbContext : DbContext
{
/// <summary>
/// Books
/// </summary>
public DbSet<Book> Books { get; set; }
/// <summary>
/// Publishers
/// </summary>
public DbSet<Publisher> Publishers { get; set; }
/// <summary>
/// Default Constructor
/// </summary>
public BoilerplateDbContext() : base()
{
}
/// <summary>
/// Constructor with DbContextOptions
/// </summary>
/// <param name="options">DbContextOptions</param>
public BoilerplateDbContext(DbContextOptions options) : base(options)
{
}
/// <summary>
/// Adding relationship
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Book>().HasOne(m => m.Publisher).WithMany(m => m.Books);
}
}
}