NBuilder Extensions: US Address Randomizer – Make EF Code First Drop Database Less Painful

NBuilder makes the aforementioned EF Code First pains suck less.  Less meaning that the pains still suck, but they are more tolerable.  If you’re not familiar with NBuilder, the NBuilder Website describes NBuilder as the following:

“Through a fluent, extensible interface, NBuilder allows you to rapidly create test data, automatically assigning values to properties and public fields that are of type of the built in .NET data types (e.g. ints and strings). NBuilder allows you to override for properties you are interested in using lambda expressions.”

In .Net 3.5 an entirely new date/time field was added called DateTimeOffset. This data extends the DateTime to add in the concept of a timezone offset. It is still a struct, so you need to use System.Nullable if you want to be able to have a null value. A DateTimeOffset value is not tied to a particular time zone, but can originate from any of a variety of time zones. For example, there are can multiple timezones that represent the same offset such as UTC –6:00 which can be Central Time, Central American, Saskatchewan, or Guadalajara. So you don’t know the timezone that the datetime represents, but you do know the offset. This is all you need to perform comparisons to other DateTimeOffsets.