NOODB: Collections Finally Work

Collections were really tedious. I’m going to have to go back and do some refactoring.

These test demonstrate 3 things:

  1. Saving a collection directly
  2. Saving a collection as a property of another object
  3. Saving a custom collection directly (ie:   MyStuffCollection:Collection<MyStuff> )

Save Directly

                Collection<ThisWillBeAPain> pain = new Collection<ThisWillBeAPain>
                {
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "1"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = true, Ouchy = "2"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "3"}
                };
                client.Save(pain);
                Assert.AreEqual(3, client.GetObjects<Collection<ThisWillBeAPain>>()[0].Count);

Save as a property of another object

                OhMy my = new OhMy
                {
                    Id = Guid.NewGuid(),
                    Pains = new Collection<ThisWillBeAPain>
                    {
                        new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = true, Ouchy = "Make it stop 1"},
                        new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "Make it stop 2"},
                        new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = true, Ouchy = "Make it stop 3"},
                    }
                };

                client.Save(my);

                OhMy fromDb = client.GetObjects<OhMy>()[0];
                Assert.AreEqual(3, fromDb.Pains.Count);

Save a custom collection directly.

                ThisWillBeAPainCollection pain = new ThisWillBeAPainCollection
                {
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "1"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = true, Ouchy = "2"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "3"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "3"}
                };
                pain.FavoriteNumber = 87;
                client.Save(pain);


An array is an IList, so I’m hoping it automatically works… we’ll soon see.

Advertisements

2 Responses to NOODB: Collections Finally Work

  1. Vadim says:

    Jay, it hurts to read this code :). I don’t think I’ve seen anybody creating such a painful object. Very original.

  2. hamletcode says:

    I created those objects before I started working on the collection stuff. The alternative object name would’ve been “ThisIsGoingToSuck”, but didn’t want to be negative. I knew it was going to be a beast.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: