Aug
30
Writing the Domain Model classes: implementing Relationships (Castle MonoRail and ActiveRecord Tutorial - Part 4)
Filed on August 30th, 2007 at 5:41 pm under .NET, CastleProject, devs, Tutorials | 2 Comments
This is the fourth post of a series started with this post about a MonoRail and ActiveRecord tutorial.
Last time we wrote the Album class and we have seen how to implement the primary key mapping and simple properties mapping.
With simple properties mapping I mean the class properties that will go to map simple data type in the database. Instead with complex properties I will mean the class properties that will go to map a relationship with another table in the database.
For the album class there are simple properties (ID, Name and Year) and complex properties (Support, Artists and Genres).
The simple properties are mapped to standard data types: ID (primary key) to int, Name to string, Year to Int16.
The complex properties are mapped to object types: Support to Support Object, Artists to an IList of Artist Object and Genres to an IList of Genre objects.
Now to go on with the tutorial we should continue writing the other classes (otherwise Album class will not compile), but in this part I first want to show you how to implement relationships in your class.
For a complete introduction to relationship mapping in ActiveRecord you can look here. In this tutorial we will use the most important relationship mapping kinds: BelongsTo, HasAndBelongsToMany (simple and with an attribute).