Exemplo n.º 1
0
 static void Main(string[] args)
 {
     using (var context = new demoContext())
     {
         var defaultPrimaryKey = "test";
         var data = context.Set <item>().Find(defaultPrimaryKey);
         context.Set <item>().Remove(data);
         var item1 = new item
         {
             ItemGID = defaultPrimaryKey, ItemID = defaultPrimaryKey,
             TS      = DateTime.Now
         };
         context.Set <item>().Add(item1);
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var db = new demoContext()){
                // truy van doi tuong
                //querty
                // var s = (from p in db.Sv select p).ToList();
                // var s = (from p in db.Sv select new { p.NameSv, p.IdLopNavigation.NameLop}).ToList();

                var s = from p in db.Sv where p.NameSv == "Duy" select new { p.NameSv, p.IdLopNavigation.NameLop };

                //method

                //var s1 = db.Sv.Select (p => new { p.NameSv, p.IdLopNavigation.NameLop}).ToList();
                var s1 = db.Sv.Where(p => p.NameSv == "Duy").Select(p => new { p.NameSv, p.IdLopNavigation.NameLop });

                //
                foreach (var i in s1)
                {
                    Console.WriteLine(i.NameSv);
                }
                //S1 HOAC S2
                //
                // foreach(var i in s){
                //      Console.WriteLine(i.NameSv + " " + i.NameLop);
                // }

                //==========================================================///
                // add
                //tao moi doi tuong
                Sv sv_add = new Sv {
                    Mssv = 5, NameSv = "duytesst", Gender = true, Birthday = new DateTime(1998, 12, 12), Dtb = 8.0, IdLop = 2222
                };
                //them doi tuong trong entitys
                db.Sv.Add(sv_add);
                // dong bo tu entity ve CSDL
                db.SaveChanges();

                //delete
                // int MSSV = 1;
                // var sv_del = db.Sv.Where(p => p.Mssv == MSSV).FirstOrDefault();
                // db.Sv.Remove(sv_del);
                // db.SaveChanges();
            }
        }
 public void Save()
 {
     _context.SaveChanges();
 }
Exemplo n.º 4
0
 public void AddSv(Sv sv_add)
 {
     db.Sv.Add(sv_add);
     db.SaveChanges();
 }