Friday, June 15, 2007

I have seen several people searching for this that have reached my site.  The thought of getting the best of both SubSonic and CSLA.NET worlds has started to intrigue me.   I previous took the Subsonic templates for granted but I have spent a lot of time modifying my CSLA.NET templates and the framework.  So I am going to follow these steps to figure out how possible it was and if it really makes sense once it is done.

1.        Research the subsonic templates.  I haven’t looked at these much so I’m going to look through these to find comparisons and the differences between my CSLA.NET templates

2.       Since I obviously can’t inherit from both ActiveList/ActiveRecord and BindingListBase and BindingBase, I have to figure out what the hierarchy should be.  I am suspecting that there is a lot of common code between the two, especially when it comes to the binding and implementing the IList, IBindingLIst, etc  interfaces.

3.       Once I have the framework ready for my template, I am going to take the VB_ClassTemplate and modify it to include both references and inherit from the new base.

I should be able to have some stuff figured out over the weekend.   I’ll post the results and some downloads.  Feel free to send me your thoughts on  what you think the hybrid templates should look like.

Code Smart Not Hard

-Mike

Friday, June 15, 2007 10:54:20 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 
Friday, June 08, 2007

 

Objects that are tightly coupled to the table that they reflect can be referred to as DataObjects.  BusinessObjects, however are objects that represent a logic unit contain the attributes and methods of the business object.  Using CSLA.NET, CodeSmith Tools for code generation, and partial classes in .NET 2.0 we are able to take the benefits of code generation and a straightforward DAL with the flexibility and options needed for designing Business Objects.   Below are some of the features of my templates that allow me to generate my Business Objects based on table schema but still allow flexibility

Partial Classes

Partial Classes is a key feature to my entire code generation process. The golden rule for generating code is to “Never edit generated code”.  With partial classes this is easy.  All of my custom functionality can be put in to my “NoGen” partial class file.  All of the other features actually contol how and what is generated but I included partial classes because it really is fundamental to code generation and allows unlimited custom functionality added to a pure DataObject.

Foreign Key Fields

This started out a way to display both the key and value data of a code in a particular row.  For example if I had an Employee table with a RoleID column, I could add a RoleName “Foreign Key Field” to the template properties.  This would generate the property just like it was a column in the table.  It is really handy for binding drop down lists to your business object and wanting to display the text value somewhere else without having to go look it up again.  This feature started out as always generating the property as a string and has grown into a delimited array where I specify the column and the datatype.  Keep in mind this will generate code for the fetch, update, and insert logic.

Require Gen  Column

Sometimes I don’t want the property to be generated but I still want the fetch, insert, and update data portal functions generated.  In this case, I specify in my template properties, to skip particular property generation. Then I can create the custom property in the no-gen partial class.  One example for this is if you have a lookup id field in your table and want the property to be an enumeration instead of an integer.

“GenOnly” Tables

“GenOnly” tables are tables that I create to base my object when the data isn’t in the format I want the data displayed.  For example I had a table with 6 columns each with a date.  If I bound this to a grid, each data for a particular row would display across in column s.  However the users wanted to see each date in its own row.  I couldn’t change the format the data is stored, so I created a “GenOnly” table with the schema in the format I wanted.

MyDates Table

·         MyDateID

·         Year1Date

·         Year2Date

·         Year3Date

·         Year4Date

·         Year5Date

·         Year6Date

GenOnly_MyDates

·         MyDateID

·         YearNumber

·         YearDate

Now I can use my templates to generate my readonly collection and object classes based on the “GenOnly” table.  I then create the SELECT stored procedure to pivot the data into the format of my objects.  Lastly I can load the objects and bind it to my grid so the data displays down.  In this example the data is readonly so I didn’t need to worry about deletes and updates.  However, if I needed to that I could create the UPDATE and DELETE procs to use a CASE statement or some dynamic SQL.

I like to think you can get the best of both worlds in using a code generator to generate your objects based on table schema but still have some flexibility because something will be different. 

Code Smart Not Hard

Mike

Friday, June 08, 2007 9:54:10 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: