forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKendoGridDbContext.cs
More file actions
65 lines (55 loc) · 2.54 KB
/
KendoGridDbContext.cs
File metadata and controls
65 lines (55 loc) · 2.54 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Data.Entity;
namespace System.Linq.Dynamic.Core.ConsoleTestApp.net452.Entities
{
public partial class KendoGridDbContext : DbContext
{
public KendoGridDbContext()
: base("name=KendoGrid")
{
}
public virtual DbSet<Company> KendoGridCompany { get; set; }
public virtual DbSet<Country> KendoGridCountry { get; set; }
public virtual DbSet<Employee> Employees { get; set; }
public virtual DbSet<Function> KendoGridFunction { get; set; }
public virtual DbSet<MainCompany> KendoGridMainCompany { get; set; }
public virtual DbSet<OU> KendoGridOu { get; set; }
public virtual DbSet<Product> KendoGridProduct { get; set; }
public virtual DbSet<Role> KendoGridRole { get; set; }
public virtual DbSet<SubFunction> KendoGridSubFunction { get; set; }
public virtual DbSet<User> Users { get; set; }
public virtual DbSet<ViewEmployeeDetails> ViewEmployeeDetails { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Employee>()
.ToTable("KendoGrid_Employee");
modelBuilder.Entity<Company>()
.HasMany(e => e.KendoGridEmployee)
.WithOptional(e => e.Company)
.HasForeignKey(e => e.CompanyId);
modelBuilder.Entity<Country>()
.HasMany(e => e.KendoGridEmployee)
.WithOptional(e => e.Country)
.HasForeignKey(e => e.CountryId);
modelBuilder.Entity<Function>()
.HasMany(e => e.KendoGridEmployee)
.WithOptional(e => e.Function)
.HasForeignKey(e => e.FunctionId);
modelBuilder.Entity<Function>()
.HasMany(e => e.KendoGridSubFunction)
.WithOptional(e => e.Function)
.HasForeignKey(e => e.FunctionId);
modelBuilder.Entity<MainCompany>()
.HasMany(e => e.KendoGridCompany)
.WithOptional(e => e.MainCompany)
.HasForeignKey(e => e.MainCompanyId);
modelBuilder.Entity<Role>()
.HasMany(e => e.User)
.WithMany(e => e.Roles)
.Map(m => m.ToTable("KendoGrid_UserRoles").MapLeftKey("RoleId").MapRightKey("UserId"));
modelBuilder.Entity<SubFunction>()
.HasMany(e => e.Employee)
.WithOptional(e => e.SubFunction)
.HasForeignKey(e => e.SubFunctionId);
}
}
}