-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBITCompanyContext.cs
197 lines (154 loc) · 7.19 KB
/
DBITCompanyContext.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace IT_Companies
{
public partial class DBITCompanyContext : DbContext
{
public DBITCompanyContext()
{
}
public DBITCompanyContext(DbContextOptions<DBITCompanyContext> options)
: base(options)
{
}
public virtual DbSet<Cities> Cities { get; set; }
public virtual DbSet<Countries> Countries { get; set; }
public virtual DbSet<EmpSubs> EmpSubs { get; set; }
public virtual DbSet<Employers> Employers { get; set; }
public virtual DbSet<ItCompanies> ItCompanies { get; set; }
public virtual DbSet<Offices> Offices { get; set; }
public virtual DbSet<Positions> Positions { get; set; }
public virtual DbSet<Products> Products { get; set; }
public virtual DbSet<Subdivisions> Subdivisions { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
optionsBuilder.UseSqlServer("Server=DESKTOP-G05H9NK\\SQLEXPRESS; Database=DBITCompany; Trusted_Connection=True; ");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Cities>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.CountryId).HasColumnName("Country_id");
entity.Property(e => e.Name)
.IsRequired()
.HasMaxLength(50);
entity.HasOne(d => d.Country)
.WithMany(p => p.Cities)
.HasForeignKey(d => d.CountryId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Cities_Countries");
});
modelBuilder.Entity<Countries>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Name)
.IsRequired()
.HasMaxLength(50);
});
modelBuilder.Entity<EmpSubs>(entity =>
{
entity.ToTable("Emp_Subs");
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.EmployerId).HasColumnName("Employer_id");
entity.Property(e => e.PositionId).HasColumnName("Position_id");
entity.Property(e => e.SubdivisionId).HasColumnName("Subdivision_id");
entity.HasOne(d => d.Employer)
.WithMany(p => p.EmpSubs)
.HasForeignKey(d => d.EmployerId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Emp_Subs_Employers");
entity.HasOne(d => d.Position)
.WithMany(p => p.EmpSubs)
.HasForeignKey(d => d.PositionId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Emp_Subs_Positions");
entity.HasOne(d => d.Subdivision)
.WithMany(p => p.EmpSubs)
.HasForeignKey(d => d.SubdivisionId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Emp_Subs_Subdivisions");
});
modelBuilder.Entity<Employers>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Education)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.Name)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.Passport)
.IsRequired()
.HasMaxLength(50);
});
modelBuilder.Entity<ItCompanies>(entity =>
{
entity.ToTable("IT_Companies");
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Name)
.IsRequired()
.HasMaxLength(50);
});
modelBuilder.Entity<Offices>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Address)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.CityId).HasColumnName("City_id");
entity.Property(e => e.ItCompanyId).HasColumnName("IT_Company_id");
entity.HasOne(d => d.City)
.WithMany(p => p.Offices)
.HasForeignKey(d => d.CityId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Offices_Cities");
entity.HasOne(d => d.ItCompany)
.WithMany(p => p.Offices)
.HasForeignKey(d => d.ItCompanyId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Offices_IT_Companies");
});
modelBuilder.Entity<Positions>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Position)
.IsRequired()
.HasMaxLength(50);
});
modelBuilder.Entity<Products>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.ItCompanyId).HasColumnName("IT_Company_id");
entity.Property(e => e.Name)
.IsRequired()
.HasMaxLength(50);
entity.HasOne(d => d.ItCompany)
.WithMany(p => p.Products)
.HasForeignKey(d => d.ItCompanyId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Products_IT_Companies");
});
modelBuilder.Entity<Subdivisions>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Name)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.OfficeId).HasColumnName("Office_id");
entity.HasOne(d => d.Office)
.WithMany(p => p.Subdivisions)
.HasForeignKey(d => d.OfficeId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Subdivisions_Offices");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}