Пример #1
0
        public ActionResult Create([Bind(Include = "Id,Name,科目一,科目二,科目三")] Grand grand)
        {
            if (ModelState.IsValid)
            {
                db.Grands.Add(grand);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(grand));
        }
Пример #2
0
 public static void InsertPerson()
 {
     using (var context = new EFDContext())
     {
         context.People.Add(new Person() {FirstName = "Bob", LastName = "Rogden"});
         context.SaveChanges();
     }
 }
Пример #3
0
 public static void UpdatePerson()
 {
     using (var context = new EFDContext())
     {
         var per = context.People.FirstOrDefault();
         per.LastName = DateTime.Now.ToString();
         context.SaveChanges();
     }
 }
Пример #4
0
 //create new parent object and new children objects
 public static void CreateObjectGraph()
 {
     using (var context = new EFDContext())
     {
         var p = new Person() {FirstName = "Bob", LastName = "Rogden"};
         p.Addresses.Add((new Address(){Street = "main street"}));
         //do you have to specify the person id or Person peroperty on the address or will it just work?
         //COOL, it just works
         context.People.Add(p);
         context.SaveChanges();
     }
 }