Site Home

Introduction
Getting Started
FAQ
Downloads

Getting Started

[This guide belongs to the older version of ActiveWriter and will be updated.]

This document replicates the Getting Started document of ActiveRecord using ActiveWriter. It is assumed that you have completed instructions on that document, since some parts are omitted here.

Adding a model file to your project

  • Create a new Console Application project.
  • Add minimum required assembly references to compile an ActiveRecord project.
  • In Solution Explorer, right click on your project.
  • Select Add / New Item...
  • Select ActiveWriter template. Name your file as Blog.actiw. Click Add.

Enabling ActiveWriter code generation

  • In Solution Explorer, click on Blog.actiw
  • In Properties window, change Custom Tool property to ActiveWriterCodeGenerator.
  • Press Enter. You will have a security warning dialog. If you want, check "Do not show this message again" checkbox. Press OK.

As soon as you change the custom tool of a project item in Visual Studio, given custom tool automatically runs against your document. ActiveWriter generates code for domain models using a custom tool class called ActiveWriterCodeGenerator. The securitiy warning is the standart warning dialog of the text templating engine of DSL Tools, which is used to create ActiveWriter.

At this stage, code is generated for the model an placed in Blog.cs file as a sub-item of the model file. Since there are no entity (or class) modelled on the modelling surface, .cs file will be nearly empty. One thing to note is that, the namespace is defined by the project environment and used as is in ActiveWriter generated code. Rgiht now, there's no option to change the namespace through the editor.

Adding model classes using Server Explorer

  • Open Server Explorer (if it's not visible, open through View / Server Explorer menu item)
  • If not done before, add a connection to the Blog (or your database, if different) database.
  • Expand Blog / Tables tree.
  • Select Blogs and Posts tables, and drag-and-drop them to the model.
  • Arrange classes so that they no longer overlap.

When you drop table or tables to the model, ActiveWriter walks the Server Explorer hierarchy to extract some information. During this process, there may be somewhat annoying flicker in Server Explorer window. This is normal, and ActiveWriter will behave more screen friendly in the future. This behaviour is more evident if there's a connection with many tables, placed above the dropped tables' connection in Solution Explorer.

After the walk, ActiveWriter then connects to the model database through the connection already defined in Server Explorer. It gathers necessary information on columns, keys and foreign key relations to construct the model. ActiveWriter does not cache this information, so it will connect again if you drop another table to the model later.

Examining model and changing properties

  • Double click on Blogs model class' name at the top to change it to Blog
  • Select Posts model class. Using properties window, change it's Name property to Blog.
  • Check Schema and Table properties to verify that correct database schema (owner in SQL 2000) and table name is populated.
  • Click on the many to one relation between two classes. Source Column property should read post_blogid.
  • Change all property names using Properties window, to match documentation in ActiveRecord Getting Started document mentioned above.

Note that, although post_blogid is a column in Posts table in the database, ActiveRecord did not add it to the class. Since this column is the relation between two classes, ActiveWriter used the column in many to one relation instead.

If you save the model right now, ActiveWriter will regenerate code, including two new classes decorated with ActiveRecord attributes.