示例#1
0
 private static void DbInit()
 {
     using (Applivationdb db = new Applivationdb())
     {
         db.Database.EnsureDeleted();
         db.Database.EnsureCreated();
     }
 }
示例#2
0
 private static void Read(int Id)
 {
     using (Applivationdb db = new Applivationdb())
     {
         Student stu = db.Students.Find(Id);
         Console.WriteLine(stu);
     }
 }
示例#3
0
 private static void Delete(int id)
 {
     using (Applivationdb db = new Applivationdb())
     {
         Student stu = db.Students.Find(id);
         db.Students.Remove(stu);
     }
 }
示例#4
0
 private static void Upadte(int id, string newEmail, string newName)
 {
     using (Applivationdb db = new Applivationdb())
     {
         Student stu = db.Students.Find(id);
         stu.Name  = newName;
         stu.Email = newEmail;
         db.SaveChanges();
     }
 }
示例#5
0
 public static void Create(string name, string email)
 {
     using (Applivationdb db = new Applivationdb())
     {
         Student student = new Student()
         {
             Name = name, Email = email
         };
         db.Students.Add(student);
         db.SaveChanges();
     }
 }