-
Notifications
You must be signed in to change notification settings - Fork 1
/
Schema.cs
75 lines (62 loc) · 1.51 KB
/
Schema.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
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFTest
{
public class ProductSchema : EntityTypeConfiguration<Product>
{
public ProductSchema()
{
HasKey(p => p.Id)
.Property(p => p.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(p => p.Description)
.HasMaxLength(256);
HasOptional(p => p.Seller)
.WithRequired(i => i.Product)
.Map(m => m.MapKey("ProductId"));
HasMany(p => p.Buyers)
.WithRequired(i => i.Product)
.Map(m => m.MapKey("ProductId"));
}
}
public class PersonSchema : EntityTypeConfiguration<Person>
{
public PersonSchema()
{
ToTable("Persons");
HasKey(p => p.Id)
.Property(p => p.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(p => p.Name)
.HasMaxLength(128);
}
}
public class SellerSchema : EntityTypeConfiguration<Seller>
{
public SellerSchema()
{
ToTable("Sellers");
HasKey(s => s.Id)
.Property(s => s.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(s => s.Rating);
}
}
public class BuyerSchema : EntityTypeConfiguration<Buyer>
{
public BuyerSchema()
{
ToTable("Buyers");
HasKey(b => b.Id)
.Property(b => b.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(b => b.ShipTo)
.HasMaxLength(256);
}
}
}