コード例 #1
0
        public ActionResult DeleteConfirmed(string id)
        {
            MyTable2 myTable2 = db.MyTable2.Find(id);

            db.MyTable2.Remove(myTable2);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "StudentID,StudentName,RuXueShiJian")] MyTable2 myTable2)
 {
     if (ModelState.IsValid)
     {
         db.Entry(myTable2).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(myTable2));
 }
コード例 #3
0
        public ActionResult Create([Bind(Include = "StudentID,StudentName,RuXueShiJian")] MyTable2 myTable2)
        {
            if (ModelState.IsValid)
            {
                db.MyTable2.Add(myTable2);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(myTable2));
        }
コード例 #4
0
        public void ToMapped_CopiesPropertiesByName()
        {
            var source = new MyTable()
            {
                MyString = "3"
            };
            var target = new MyTable2();

            source.MapTo(target);

            Assert.AreEqual("3", target.MyString);
        }
コード例 #5
0
        // GET: Chapter08/MyTable2/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MyTable2 myTable2 = db.MyTable2.Find(id);

            if (myTable2 == null)
            {
                return(HttpNotFound());
            }
            return(View(myTable2));
        }
コード例 #6
0
        public void ScriptDeleteFact2()
        {
            var command = new SqlCommand();
            var entity  = new MyTable2();

            entity.MyKey1 = 1;
            entity.MyKey2 = 2;

            _scripter.ScriptDelete(command, 0, entity);

            Assert.Equal(@"DELETE FROM [MyTable2] WHERE [MyKey1] = @0_0 AND [MyKey2] = @0_1;", command.CommandText.Trim());
            Assert.Equal(2, command.Parameters.Count);
            Assert.Equal("@0_0", command.Parameters[0].ParameterName);
            Assert.True(command.Parameters[0].Value.Equals(1));
            Assert.Equal("@0_1", command.Parameters[1].ParameterName);
            Assert.True(command.Parameters[1].Value.Equals(2));
        }
コード例 #7
0
 public ActionResult Create([Bind(Include = "StudentID,StudentName,Sex,RuXueShiJian")] MyTable2 myTable2)
 {
     if (ModelState.IsValid)
     {
         try
         {
             db.MyTable2.Add(myTable2);
             db.SaveChanges();
         }
         catch (DataException err)
         {
             ModelState.AddModelError("StudentID", "(已存在该学号,不能重复添加)。\n" + err.Message);
             return(View(myTable2));
         }
         return(RedirectToAction("Index"));
     }
     return(View(myTable2));
 }
コード例 #8
0
        public void ScriptInsertFact2()
        {
            var command = new SqlCommand();
            var entity  = new MyTable2();

            entity.MyKey1   = 1;
            entity.MyKey2   = 2;
            entity.MyString = "test";

            _scripter.ScriptInsert(command, 0, entity, false);

            Assert.Equal(@"INSERT INTO [MyTable2] ([MyKey1], [MyKey2], [MyString]) VALUES (@0_0, @0_1, @0_2);", command.CommandText.Trim());
            Assert.Equal(3, command.Parameters.Count);
            Assert.Equal("@0_0", command.Parameters[0].ParameterName);
            Assert.True(command.Parameters[0].Value.Equals(1));
            Assert.Equal("@0_1", command.Parameters[1].ParameterName);
            Assert.True(command.Parameters[1].Value.Equals(2));
            Assert.Equal("@0_2", command.Parameters[2].ParameterName);
            Assert.True(command.Parameters[2].Value.Equals("test"));
        }
コード例 #9
0
        public void PrimaryKeyTest2()
        {
            var instance1 = new MyTable2();
            var instance2 = new MyTable2();

            instance1.MyKey1 = 1;
            instance1.MyKey2 = 2;

            instance2.MyKey1 = 3;
            instance2.MyKey2 = 4;

            Assert.AreEqual(instance1.Entity.PrimaryKey.Length, 2);
            Assert.AreEqual((int)instance1.Entity.PrimaryKey[0], 1);
            Assert.AreEqual((int)instance1.Entity.PrimaryKey[1], 2);

            Assert.AreEqual(instance2.Entity.PrimaryKey.Length, 2);
            Assert.AreEqual((int)instance2.Entity.PrimaryKey[0], 3);
            Assert.AreEqual((int)instance2.Entity.PrimaryKey[1], 4);

            Assert.AreNotEqual(instance1, instance2);
        }
コード例 #10
0
        public void ScriptUpdateFact2()
        {
            var command = new SqlCommand();
            var entity  = new MyTable2();

            entity.MyKey1 = 1;
            entity.MyKey2 = 2;
            entity.Entity.Reset();

            entity.MyString = "test";

            _scripter.ScriptUpdate(command, 0, entity);

            Assert.Equal(@"UPDATE [MyTable2] SET [MyString] = @0_0 WHERE [MyKey1] = @0_1 AND [MyKey2] = @0_2;", command.CommandText.Trim());
            Assert.Equal(3, command.Parameters.Count);
            Assert.Equal("@0_0", command.Parameters[0].ParameterName);
            Assert.True(command.Parameters[0].Value.Equals("test"));
            Assert.Equal("@0_1", command.Parameters[1].ParameterName);
            Assert.True(command.Parameters[1].Value.Equals(1));
            Assert.Equal("@0_2", command.Parameters[2].ParameterName);
            Assert.True(command.Parameters[2].Value.Equals(2));
        }
コード例 #11
0
 public void Add(MyTable2 anything)
 {