Exemplo n.º 1
0
 static List <Student> Get()
 {
     using (var ctx = new EFCoreDemoDbContext())
     {
         return(ctx.Student.Where(p => p.FirstName == "zhang").ToList());
     }
 }
Exemplo n.º 2
0
 static void Update()
 {
     using (var ctx = new EFCoreDemoDbContext())
     {
         var student = ctx.Student.First(p => p.FirstName == "zhang");
         if (student != null)
         {
             student.LastName = "san_new";
             ctx.SaveChanges();
         }
     }
 }
Exemplo n.º 3
0
 static void Delete()
 {
     using (var ctx = new EFCoreDemoDbContext())
     {
         var student = ctx.Student.FirstOrDefault(p => p.FirstName == "li");
         if (student != null)
         {
             ctx.Student.Remove(student);//或者:ctx.Remove<Student>(student);
             ctx.SaveChanges();
         }
     }
 }
Exemplo n.º 4
0
        static void Add()
        {
            using (var ctx = new EFCoreDemoDbContext())
            {
                var student = new Student
                {
                    FirstName = "li",
                    LastName  = "si"
                };

                ctx.Student.Add(student);//或:ctx.Add<Student>(student);
                ctx.SaveChanges();
            }
        }