-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathEmployeesContext.cs
59 lines (46 loc) · 2.02 KB
/
EmployeesContext.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
54
55
56
57
58
59
using HappyCode.NetCoreBoilerplate.Core.Models;
using Microsoft.EntityFrameworkCore;
namespace HappyCode.NetCoreBoilerplate.Core
{
public partial class EmployeesContext : DbContext
{
public EmployeesContext(DbContextOptions<EmployeesContext> options)
: base(options)
{
}
public virtual DbSet<Department> Departments { get; set; }
public virtual DbSet<Employee> Employees { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
modelBuilder.Entity<Department>(entity =>
{
entity.HasIndex(e => e.DeptName)
.HasDatabaseName("dept_name")
.IsUnique();
entity.HasIndex(e => e.MangerNo)
.HasDatabaseName("manger_no");
entity.Property(e => e.DeptNo).ValueGeneratedNever();
entity.Property(e => e.DeptName).IsUnicode(false);
entity.HasOne(d => d.Manger)
.WithMany(p => p.LeadingDepartments)
.HasForeignKey(d => d.MangerNo)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("departments_ibfk_1");
});
modelBuilder.Entity<Employee>(entity =>
{
entity.HasIndex(e => e.DeptNo)
.HasDatabaseName("dept_no");
entity.Property(e => e.EmpNo).ValueGeneratedOnAdd();
entity.Property(e => e.FirstName).IsUnicode(false);
entity.Property(e => e.LastName).IsUnicode(false);
entity.HasOne(d => d.Department)
.WithMany(p => p.Employees)
.HasForeignKey(d => d.DeptNo)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("employees_ibfk_1");
});
}
}
}