-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
CarsContext.cs
43 lines (34 loc) · 1.35 KB
/
CarsContext.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
using HappyCode.NetCoreBoilerplate.Core.Models;
using Microsoft.EntityFrameworkCore;
namespace HappyCode.NetCoreBoilerplate.Core
{
public partial class CarsContext : DbContext
{
public CarsContext(DbContextOptions<CarsContext> options)
: base(options)
{
}
public virtual DbSet<Car> Cars { get; set; }
public virtual DbSet<Owner> Owners { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
modelBuilder.Entity<Car>(entity =>
{
entity.Property(e => e.Model).IsUnicode(false);
entity.Property(e => e.Plate).IsUnicode(false);
entity.HasOne(d => d.Owner)
.WithMany(p => p.Cars)
.HasForeignKey(d => d.OwnerId)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("FK_Cars_Owners");
});
modelBuilder.Entity<Owner>(entity =>
{
entity.Property(e => e.FirstName).IsUnicode(false);
entity.Property(e => e.FullName).IsUnicode(false);
entity.Property(e => e.LastName).IsUnicode(false);
});
}
}
}