Auto-generate Your Data Access Code




Auto-generate Your Data Access Code


By Brian Noyes


Some of the most mundane, tedious, and error-prone coding you must do in every serious application is to create the data access code that will provide run-time data for your application and persist that data back to a data store when needed. ADO.NET alleviates some of the pain by providing a consistent, easy to use, object-oriented model for data access to relational data stores. But you still end up having to code the same patterns over and over to manage your data. RapTier by SharpPower can make it so you never have to write data access code again.


RapTier is a code-generation product that has a host of features focused on automating the creation of data access code, database scripts, documentation, and even simple data access user interfaces. To use the product, you simply create a project in RapTier, point to a database, and select the desired options for code generation (see Figure 1). The core functionality of RapTier is to generate a .NET data access layer in either C# or VB.NET that is based on the Table Data Gateway enterprise design pattern described by Martin Fowler in his book Patterns of Enterprise Application Architecture (Addison-Wesley, 2002). RapTier generates a clean, consistent set of classes for each table, view, or stored procedure you select and allows you to retrieve all rows or one specific row, and then push updates, inserts, and deletes back to the database when needed.


Figure 1: Generate all your data access code for your application and your database in one simple step.


RapTier-generated code allows you to work with the data in the form of ADO.NET DataTables, or as strongly typed collections of business objects. It splits the code into a base class for each data collection that contains the core generated code, and a derived class where you can add your own business logic or validation code. It allows you to regenerate the code if your schema changes and it maintains old and new versions so you don't have to worry about losing your custom code. And you can work with your entire database as a project, doing the code generation in one fell swoop, instead of one table at a time (as with some other data access code generators).


The data access layer code generation alone is worth the price, but there is a lot more to the product. The next best feature for me is the ability to automatically create stored procedures to wrap any table or view. This makes it easy to enforce a stored procedure-only data access strategy for your database without having to code all the standard CRUD procedures yourself. You can also automatically generate MSDN-like database documentation that you can navigate in a browser. It extracts all the schema information, making it easy to discover information about the database, without requiring access to SQL Enterprise Manager or another tool.


The project generated for data access code also can include a Web and/or Windows UI project that lets you perform form and grid-based navigation and management of the underlying data. The generated code is useful for learning how to code against the generated data access layer, and can also be used to cut and paste the forms in the designer to save some time laying out your own UIs. However, most real apps are going to need to perform their own layout and may not include all fields, so this really just provides a good starting point, not a finished product. But it still results in yet more time savings in developing your data-driven applications.


Overall, I found RapTier to be a simple to use, but powerful tool. The documentation is fairly detailed, although not overwhelming because the tool itself is so easy to use. If you aren't extremely picky about the shape or naming of your coding artifacts, you can use the functionality out of the box to save immense amounts of time. If you want to customize things, the code generation process is all driven by customizable and extensible templates, so you can easily change things like naming conventions and commenting, and you can also change the entire code-generation process with a bit more effort. If you are tired of writing CRUD code and would like to spend your time focusing on application code, I recommend you check out RapTier. (There's a free version available, which limits the number of tables and views you can work with in a project.)



Web Site: http://www.sharppower.com

Price: US$299



Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.