How it works
The ActiveRecord framework collects information about your classes, tries to infer some meaning and generates the correct mapping for NHibernate. By doing this, ActiveRecord does not require that you make everything explicit, thus saving your time. ![]()
ActiveRecord also hides some complexity in favor of more natural code, which you will see in the next following sections.
How it handles mappings
When you invoke ActiveRecordStarter.Initialize, the framework will inspect the set of types. As a matter of fact it uses the ActiveRecordModelBuilder, which creates a ActiveRecordModel that has all information about the type (primary key, mapped properties, relations, validations and so on).
After that ActiveRecordStarter executes visitors on the set of ActiveRecordModel just created. Each visitor is concerned about some specific task.
- GraphConnectorVisitor: connects the types based on relation information, like connection Blog to Post. This makes some tasks simpler later
- SemanticVerifierVisitor: based on the information on the model, validates it and throw exception with clear messages whenever something is not right.
- XmlGenerationVisitor: generates the Xml expected by NHibernate
How scopes work
TODO
Reference Articles
Hammett has two blog posts explaining how Active Record works internally:
