-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddress.cs
More file actions
60 lines (48 loc) · 1.52 KB
/
Address.cs
File metadata and controls
60 lines (48 loc) · 1.52 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
using Microsoft.EntityFrameworkCore;
namespace ECommercePersistence.Model;
public class Address
{
public string? Id { get; set; }
public string? CustomerId { get; set; }
public string? Code { get; set; }
public string? City { get; set; }
public string? State { get; set; }
public string? Street { get; set; }
public DateTimeOffset? UpdatedOn { get; set; }
public DateTimeOffset CreatedOn { get; set; }
public Customer? Customer { get; set; }
internal static void Builder(ModelBuilder x)
{
x.Entity<Address>().HasKey(x => x.Id);
x.Entity<Address>()
.Property(x => x.Id)
.HasMaxLength(36)
.IsRequired();
x.Entity<Address>()
.Property(x => x.CustomerId)
.HasMaxLength(36)
.IsRequired();
x.Entity<Address>()
.Property(x => x.Street)
.HasMaxLength(100)
.IsRequired();
x.Entity<Address>()
.Property(x => x.Code)
.HasMaxLength(50)
.IsRequired();
x.Entity<Address>()
.Property(x => x.City)
.HasMaxLength(50)
.IsRequired();
x.Entity<Address>()
.Property(x => x.State)
.HasMaxLength(50)
.IsRequired();
x.Entity<Address>()
.HasOne(c => c.Customer)
.WithMany(c => c.Addresses)
.HasForeignKey(c => c.CustomerId)
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
}
}