Ejemplo n.º 1
0
        private static void UpdateStudent()
        {
            using (EFDBEntities db = new EFDBEntities())
            {
                db.Database.Log = Console.WriteLine;
                Students student = db.Students.Where(s => s.StudentId.Equals(100024)).FirstOrDefault();
                student.StudentName = "修改后的对象1";

                int result = db.SaveChanges();
                Console.WriteLine(result);
                Console.Read();
            }
        }
Ejemplo n.º 2
0
        private static void DeleteStudent()
        {
            using (EFDBEntities db = new EFDBEntities())
            {
                db.Database.Log = Console.WriteLine;

                Students student = new ExecuteStoredProcedure.Students {
                    StudentId = 100024
                };

                db.Students.Attach(student);
                db.Students.Remove(student);

                int result = db.SaveChanges();
                Console.WriteLine(result);
                Console.Read();
            }
        }
Ejemplo n.º 3
0
        private static void AddStudent()
        {
            using (EFDBEntities db = new EFDBEntities())
            {
                db.Database.Log = Console.WriteLine;
                db.Students.Add(new Students
                {
                    StudentName    = "新添加的对象1",
                    Age            = 20,
                    Birthday       = Convert.ToDateTime("1998-01-01"),
                    ClassId        = 2,
                    PhoneNumber    = "13022202050",
                    StudentAddress = "天津",
                    Gender         = "男",
                    StudentIdNo    = 130229199801011220
                });

                int result = db.SaveChanges();
                Console.WriteLine(result);
                Console.Read();
            }
        }