Пример #1
0
        public void UpdatePartial()
        {
            // Create and insert the person
            var person = new Person { Id = Guid.NewGuid(), Name = "PetaPoco", Dob = new DateTime(2011, 1, 1), Age = (DateTime.Now.Year - 2011), Height = 242 };
            var id = DB.Insert(person);

            // Update a few properties of the person
            person.Age = 70;
            person.Name = "The PetaPoco";

            // Get the poco data
            var pocoData = PocoData.ForType(person.GetType(), DB.DefaultMapper);

            // Tell PetaPoco to update only ther person's name
            // The update statement produced is `UPDATE [People] SET [FullName] = @0 WHERE [Id] = @1`
            DB.Update(person, new [] { pocoData.GetColumnName(nameof(Person.Name)) });

            // Get a clone/copy from the DB
            var clone = DB.Single<Person>(id);

            // See, the person has been updated, but only the name
            clone.Id.ShouldBe(person.Id);
            clone.Dob.ShouldBe(person.Dob);
            clone.Height.ShouldBe(person.Height);

            clone.Age.ShouldNotBe(70);
            clone.Name.ShouldBe("The PetaPoco");
        }