-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (61 loc) · 1.77 KB
/
Program.cs
File metadata and controls
75 lines (61 loc) · 1.77 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCodeFirstTest
{
class Program
{
static void Main(string[] args)
{
using (var ctx = new MyContext())
{
var company = new Company()
{
Name = "公司名称",
Descript = "公司描述"
};
ctx.Company.Add(company);
ctx.SaveChanges();
}
}
}
public class MyContext : DbContext
{
public MyContext() : base("name=default") { }
public virtual DbSet<Company> Company { get; set; }
public virtual DbSet<Employee> Employee { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
public class Company
{
[Key]
public long ID { get; set; }
[DisplayName("名称"), Required, StringLength(50)]
public string Name { get; set; }
[DisplayName("描述")]
public string Descript { get; set; }
}
public class Employee
{
[Key]
public long ID { get; set; }
public long CompanyID { get; set; }
public Company Company { get; set; }
[DisplayName("名称"), Required, StringLength(50)]
public string Name { get; set; }
[DisplayName("性别")]
public int Gender { get; set; }
[DisplayName("身高")]
public int Height { get; set; }
[DisplayName("体重")]
public decimal Weight { get; set; }
}
}