ActiveWriter is an addon (a package, actually) which extends Visual Studio 2005 to provide modeling functionality for Castle ActiveRecord and NHibernate. In Visual Studio 2005, you can add an ActiveWriter file C# and VB.NET project kinds like windows, web, class library etc. You can add more then one ActiveWriter file to a project.
Code Generation Model
ActiveWriter includes a code generator to transform the model you designed into something useful, the code.

When you are done, or partially done, with your model saving the model file in Visual Studio automatically triggers code generation. During the code generation phase, a .cs or.vb file based on the project type in Visual Studio is generated. This file contains all the classes, properties, some helper methods and necessary attributes generated based on your model. All the generated code per .actiw file gets written in a single .cs or .vb file. Currently, there's no way to generate separate files for each class.
Notice
ActiveWriter is a one-way generator. This means that any modifications to the generated files will be overridden when you save your model file. To overcome this limitation, all the classes generated by ActiveWriter are partial. You may add your own code to the generated class in a separate partial file.
Model Surface

When you add an ActiveWriter file, you will actually have two new files in your project:
- Model file (with .actiw extension): An XML file defining the model entities and relations in ActiveWriter dialect.
- Designer definitions (with .actiw.diagram extension): An XML file keeping the placement etc. of items on the model surface.
Model surface is the designer for ActiveWriter files, associated with .actiw files in visual studio.

You can drag items from Toolbox, or drag tables from Server Explorer onto the surface to create entities and relations. You can select any visual element and view or edit it's properties through Properties Window. Right clicking on items or the design surface provides associated commands, such as adding a new Property to an entity or validating the model etc.
Toolbox

The items in the toolbox basically shows the capabilities of ActiveWriter, what you can model with it:
- Class: Defines a class (or entity) of your model.
Classes are the main focus points in ActiveWriter. You link classes to classes, you add properties to them, connect them with nested data. Based on your selections, code generator creates at least one class declaration (two, for example, when you have composite keys) per model class. - Nested Class: Defines a nested class
, a class where you can use to extract chunks of data to an external class. - Many To One Relationship: HasMany
/ BelongsTo
relations between classes - Many To Many Relationship: HasAndBelongsToMany
relations between classes - One To One Relationship: OneToOne
relations between classes - Nested Relationship: Nested relations between a class and a nested class
You can drag classes and nested classes directly to the design surface. Relations, however, should be used by selecting a source and a target entity.
Validation
Model validation is automatically initiated when you open and save a model. You may also validate your model by using the context menu on the model surface. You can find validation errors in Error List toolwindow of Visual Studio. If appropriate, AcitveWriter will select the problematic visual element (class, property etc.) when you double click on the validation error. Although you may continue saving a model while there are validation errors, code generation will most likely fail.
Available validations are:
Model
- ActiveRecord assembly name should be supplied when the target is NHibernate
- NHibernate assembly name should be supplied when the target is NHibernate
- Use Virtual Properties should set to true if the model contains at least one class with virtual set to true
Class
- Each class must have a name
- Each class must have a unique name in a model
- Class names should not contain spaces
- Class names should not start with a number
- Class should have at most one property as the primary key
- For composite keys, at least two properties should be set as composite key in a class
- Class should not have both primary key and composite key properties at the same time
- All composite keys in a class should have the same access type
- Only one property in a class should be set with the DebuggerDisplay
attribute
Property
- Each property must have a name
- Each property must have a unique name in a class
- Property names should not contain spaces
- Property names should not start with a number
- If generator is sequence, a sequence name should be supplied
- Version or Timestamp property types should not be marked as keys
- Composite keys cannot be marked with DebuggerDisplay attribute
- Versions and timestamps should be one of the following column types: Int64, Int32, Int16, Ticks, Timestamp, or TimeSpan
- If column type is custom, CustomColumnType and CustomMemberType must be set
- Properties with custom types cannot be marked as keys
Nested Class
- Nested classes should not have key properties
- Only one property in a nested class should be set with the DebuggerDisplay attribute
Relations
- Table name, source column and target column should be set in a many to many relation
- Column key and column name should match in a many to one relation
- A class cannot make a one to one relation with itself
- Two classes should not have circular one to one relationship with each other
Code Generation

As noted before, code generation takes place when you save your model. If anything goes wrong, you may find the error message in Error List toolwindow, as usual. Behind the scenes, ActiveWriter use a custom tool, called ActiveWriterCodeGenerator, associated with your .actiw file in the designer to initiate the code generation process. By default, ActiveWriter file template in Visual Studio automatically set this property when you add a new .actiw file to your project.
The generated .cs or .vb file is hierarchically attached to your .actiw file in the Solution Explorer (see Solution Explorer screenshot above). Currently, there's no option to set output path to a different place. If you select NHibernate as the target, one .hbm.xml file per entity will also be generated and attached to the same .actiw file along with the .cs or .vb file, you have the option to control the attachment of .hbm.xml files though.

After working with Entity with relational databases when I dragged all my sql tables onto the designer and watched it get the mapping right right off the bat I was really impressed.