![]() | ![]() The Castle ActiveRecord project is an implementation of the ActiveRecord pattern for .NET. The ActiveRecord pattern consists on instance properties representing a record in the database, instance methods acting on that specific record and static methods acting on all records. Castle ActiveRecord is built on top of NHibernate, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly. Warning
Although ActiveRecord makes using NHibernate easy it does not hide all details of NHibernate behaviour. You need to understand NHibernate flushing behaviour and how to work with text/ntext columns. |
![]() | Getting StartedOur ActiveRecord Getting Started is the best source of information for newcomers. You will be acquainted with the project in small steps. After that you can (and should) always consult the documentation for more in-depth information. |
![]() | DocumentationCastle ActiveRecord is fully documented. The documentation is versioned based on the released version. You should also take time to read the FAQ and the project's Roadmap. |
![]() | Why would I use it?With Castle ActiveRecord you won't have to learn NHibernate mapping schema to have a working data access layer in minutes. For most cases you won't need to deal with ISession and ISessionFactory. Most of the complexity is handled by ActiveRecord, but if you want to do something more advanced, you will be able to do it. Castle ActiveRecord offers a subset of NHibernate mapping functionality. We focused on covering the regular mappings used by most developers. Mapping is done using class, fields and property level attributes. ActiveRecord is able to infer table and column names if you omit them. Just to give you a taste, the following is an example of an ActiveRecord class. [ActiveRecord] public class Category : ActiveRecordBase { private int id; private string name; private Category parent; private IList<Category> subcategories = new List<Category>(); [PrimaryKey] public int Id { get { return id; } set { id = value; } } [Property] public string Name { get { return name; } set { name = value; } } [BelongsTo("parent_id")] public Category Parent { get { return parent; } set { parent = value; } } [HasMany] public IList<Category> SubCategories { get { return subcategories; } set { subcategories = value; } } } The generic base classes is even better. You can have the most common operations for free. You just need to take care of the mapping. The following is an example using ActiveRecordBase<>. [ActiveRecord] public class Blog : ActiveRecordBase<Blog> { private int id; private string name; private string author; [PrimaryKey] public int Id { get { return id; } set { id = value; } } [Property] public string Name { get { return name; } set { name = value; } } [Property] public string Author { get { return author; } set { author = value; } } } Using a base class is not an obligation, though. You can still benefit from ActiveRecord without forcing your class to extend ActiveRecordBase. Curious? Check our documentation. |
![]() | Why would I not use it?Complex databases structures (legacy databases mostly) usually are not covered by the range of mapping features supported by ActiveRecord. In this case you might consider using NHibernate directly. Batch operations, like importing or exporting thousands of records, should not rely on ActiveRecord nor on NHibernate. For those situations you might consider using pure ADO.Net. |
VersionThe latest release is 1.0 Release Candidate 2 | |
ActiveRecord Site MapIf you want to find some document fast, you might want to check the ActiveRecord site map. | |





