Codefirst Fluent API创建关系

class People
2 {
3 public int Id { get; set; }
4 public string Name { get; set; }
5 public DateTime Birth { get; set; }
6 public bool Sex { get; set; }
7 public string Description { get; set; }
8 }
9
10 class myContext : DbContext
11 {
12 public DbSet<People> peopleSet { get; set; }
13 protected override void OnModelCreating(DbModelBuilder modelBuilder)
14 {
15 modelBuilder.Configurations.Add(new PeopleConfig());
16 }
17 }
18
19 class PeopleConfig : EntityTypeConfiguration<People>
20 {
21 public PeopleConfig()
22 {
23
24 Map(m =>
25 {
26 m.Properties(p => new { p.Sex, p.Name });
27 m.ToTable("Person");
28 });
29
30 Map(m =>
31 {
32 m.Properties(p => new {p.Description, p.Birth });
33 m.ToTable("Detail");
34 });
35 }
36 }
原文地址:https://www.cnblogs.com/lxiang/p/2479104.html