Random Dev Notes

January 7, 2010

IQToolkitCodeGen (alpha version)

Filed under: Development — Tags: , , — Tom Brothers @ 11:40 am

When I first started using LINQ to VFP I didn’t mind manually writing Entity classes and mapping the data but after awhile I found it to become a tedious task.  So I decided to write a code generation application that would work with LINQ to VFP and the IQToolkit SQL Server Provider.  This application has really turned out to be a play thing for me so that I can get some hands on learning with WPF and Spark View Engine.  But before I’d allow myself to get to far into playing around I wanted to make sure I got the core functionality done.  At this point I have an alpha build available for anyone interested. 


Settings Overview:


As expected, you can use a full connection string to access VFP or SQL Server.  There are also a few unconventional connection options.  You can specify the full path to a dbc file or a specify a directory for free tables.  Both of these options will be used to create a connection string for VFP.  You can also provide a modified version of a SQL Server connection string that includes a pipe delimited list of databases (Example:  Data Source=.;Initial Catalog=Northwind|AspNet;Integrated Security=True). 

The Data Context Settings were designed with two different Data Contexts types in mind.  The first Data Context is an Entity Provider which is basically a class that has a property for each Entity.  This type of Data Context is what the IQToolkit Tests use.  The other type of Data Context is a based on a Repository Pattern which uses Generic methods instead of accessing an Entity property. 

The Data Context Settings allow you to specify the class name, output file, and namespace for both types of these Data Contexts.  The Base Class setting is for the Repository Data Context.

The Entity Settings allow you to specify the file extension, namespace, output path, and template.  There is only one Entity template available. 
The Mapping Settings can be used to create an Attribute Mapping class or an Xml Mapping file.

By default, the Entity Provider Template was designed to work with the Attribute Mapping Template and the Repository Provider Template was designed to work with the Xml Mapping Template.

Getting Started:

Enter all the setting values and then click the Load Data button.  Then the grids will be populated with the Tables, Columns, and Associations information.

The Tables grid is pretty simple to use.  Just check the checkbox in the Include column if you want an Entity class created.  The Entity class name can be specified using the grid’s Entity Name column.


The Columns grid shows the Columns of the selected row in the Tables grid.  This grid has a few more available options than the Table grid but is just as easy to use.  Check the checkbox in the Include column if you want the Entity class to include the property for the selected column.  In this grid, you can also change the name and type of the property as well as identify the primary key and indicate if it is an auto generated key.


The last grid shows the Associations.  This grid has an Include column and a Property Name column that can be set.


Click the Generate Files button after all the mapping information has been entered to complete the process.

Don’t like my templates?

The template files are distributed with this application so feel free to modify the templates as needed. Additionally, if you feel that you need to add a new template just add it to the appropriate folder and it will show up in the combo box after resetting the application.

This is a diagram shows the Template classes along with classes that they reference.



  1. Tom,

    I desperately need your help. Being able to use this code generator would save me a lot of time on a new project that is starting today. I have got it connection to my DBF files, and can see the columns, but I always get a Method Not Found: System.Web.RazorTemplateEngine.GenerateCode(…). I have the latest RTM of MVC 3, and have all the Razor files in my GAC. Was this version built with an old MVC release? Do you have any other ideas?

    Thank you so much,
    Brian Clark

    Comment by Brian Clark — May 17, 2011 @ 1:35 am

    • I believe that I have the latest version of Razor. But just in case, I changed the build to include the Razor.dll and posted a new build. See if that works for you.

      Comment by Tom Brothers — May 17, 2011 @ 11:17 am

  2. Tom,

    Thank you for the quick response. After comparing the Razor.dll’s, turns out I was the one running the old RC version instead of the RTM. Sorry for the hassle, I have gotten it to do some basic generation. One more question though. Is there any way to specify naming conventions? E.g TitleCase? If not thats fine, its still a huge time saver.


    Comment by Brian Clark — May 17, 2011 @ 6:05 pm

  3. Nevermind, I just noticed the property names are editable. Great work.

    Comment by Brian Clark — May 17, 2011 @ 6:07 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: