We've all been there. We add a field to a SQL Table because our business object needs a new property, which means we have to change the business object and include the new property or properties in the various processes where the object is being populated or created. I was in this situation today with a Community Server project.
I used Drive to do the job and took a few snapshots along the way to provide a pictorial record of how the CodeSmith templates in Drive knock out everyday Community Server development tasks like handling data object changes.
Our Business Object is a "DirectoryPost," an extension of the WeblogPost object. We add our field in the SQL utility table (created from a view) to get things underway. We're treating a Community Server blog as an advertising directory in our custom application, and we need an "IsCourtesyAdvertisement" DirectoryPost property.
Time to update the DirectoryPost business object. We'll use the Drive "Create Business Object" template.
Below is the generated code output. We'll simply replace the existing DirectoryPost.cs class with the code we just created.
Now we need to handle the property when populating a DirectoryPost object or when creating or updating the data in the SQL Data Provider. Drive includes a number of Utility templates that generate the code for exactly these functions. We'll generate a fresh PopulateDirectoryPost() method with the "Populate Business Object Method" template.
Finally we need to create the SQL Command Parameters for our new IsCourtesyAdvertisement property. We'll use the "Create Parameters for Object" template for that.
Drive also contains CodeSmith snippets to generate code for the new property when, say, updating a custom Chameleon Subform, which is something else I did with IsCourtesyAdvertisement today. More on Drive snippets another time.
There, I told you this post was mostly pictures.