EF学习记录
1.四种模型区别
1.Database First学习链接:
https://www.cnblogs.com/1175429393wljblog/p/10775763.html
2.Model First学习链接:
http://www.10qianwan.com/articledetail/42545.html
https://www.cnblogs.com/1175429393wljblog/p/10775251.html
3.Code First学习链接:
https://www.cnblogs.com/alunchen/p/6903753.html
控制台命令输入
增删改查:
//增 private void button1_Click(object sender, EventArgs e) { using (MyModel mymodel = new MyModel()) { mymodel.Schools.Add(new School() { Key = 2, Name = "画川中心", Uid = 1 }); mymodel.SaveChanges(); } } //查 private void button2_Click(object sender, EventArgs e) { using (MyModel mymodel = new MyModel()) { dataGridView1.DataSource = mymodel.Schools.ToList(); } } //删 private void button4_Click(object sender, EventArgs e) { using (MyModel mymodel = new MyModel()) { mymodel.Schools.Remove(mymodel.Schools.FirstOrDefault(x => (x.Key==1))); mymodel.SaveChanges(); } } //改 private void button3_Click(object sender, EventArgs e) { using (MyModel mymodel = new MyModel()) { var model= mymodel.Schools.Where(x => (x.Key == 1)).FirstOrDefault(); model.Name = "宝应中学"; mymodel.SaveChanges(); } }