예제 #1
0
        public void Insert()
        {
            // Create the person
            var person = new Person { Id = Guid.NewGuid(), Name = "PetaPoco", Dob = new DateTime(2011, 1, 1), Age = (DateTime.Now.Year - 2011), Height = 242 };

            // Tell PetaPoco to insert it
            var id = DB.Insert(person);

            // Obviously the ID returned will be the same at the one we set
            id.ShouldBe(person.Id);

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

            // See, they're are the same
            clone.ShouldBe(person);

            // But, they're not not reference equals as PetaPoco doesn't cache because it's a MircoORM.
            person.Equals(clone).ShouldBeFalse();
        }
예제 #2
0
        public void InsertToDifferentTable()
        {
            // Create the person
            var person = new Person { Id = Guid.NewGuid(), Name = "PetaPoco", Dob = new DateTime(2011, 1, 1), Age = (DateTime.Now.Year - 2011), Height = 242 };

            // Tell PetaPoco to insert it, but to the "SpecificPeople" table and not the "People" table.
            // Note: the id will only be returned if PetaPoco can tell which is the primary key via mapping or convention.
            var id = DB.Insert("SpecificPeople", person);

            // Obviously the ID returned will be the same at the one we set
            id.ShouldBe(person.Id);

            // Get a clone/copy from "People" table (Default table as per mappings)
            var clone = DB.SingleOrDefault<Person>(id);

            // As expected, doesn't exist
            clone.ShouldBeNull();

            // We need to get the clone/copy from the correct table
            // Note: we can't use auto select builder here because PetaPoco would create columns such as People.Id
            clone = DB.Query<Person>("SELECT * FROM [SpecificPeople] sp WHERE sp.[Id] = @0", id).Single();

            // See, they're are the same
            clone.ShouldBe(person);

            // But, they're not not reference equals as PetaPoco doesn't cache because it's a MircoORM.
            person.Equals(clone).ShouldBeFalse();
        }