Introduction Source: http://www.cnblogs.com/zxj159/p/4082987.html
One, active record (activity recording) mode
Active Record is one of the most common framework patterns in the business logic layer (the Enterprise Application architecture model is classified as a data source pattern), especially when the underlying database model matches the business model, which is a database-driven framework pattern.
Typically, each table in the database corresponds to a business object. A business object represents a row in a table and contains data, behavior, and tools to persist the object, as well as the methods required to add new instances and find collections of objects.
In active record mode, each business object is responsible for its own persistence and related business logic.
Active record mode is ideal for simple applications that have a one-to-one mapping between the data model and the business model, such as blogs or forums.
Because business objects have a one-to-one mapping to tables in a database and all have the same crud methods, you can use code generators to automatically generate business models.
Objects in Active record mode typically contain CRUD operations to perform database operations, as well as related validation and business-related calculation and inspection capabilities.
In particular, the typical active record class also contains some instance properties that represent the columns in the data table and an instance method that operates on the current object. The Active record class may also contain static methods to manipulate all records on the datasheet. (The following actual operation may be very helpful to understand this sentence)
Advantages of the 1.Active record
The success of an Active record relies on two factors: simplicity and framework. The Active record concept is very simple to understand, but it still requires a lot of code if implemented manually.
Writing and maintaining each class requires a lot of code, but this is only the minimum requirement, because you might also want to consider adding one or more data migration objects (DTOS) for each class or data table.
Admittedly, the record of activity does find a good balance between simplicity and the power of the final system. And the model also waits for a lot of developers to support, for example, Linq-to-sql and our today's protagonist--castle ActiveRecord.
The disadvantage of the 2.Active record
In theory, an additional layer exists between the object model and the data schema, often called the data Mapper, in development. In the active record, we can integrate the layer directly into the object, but as this layer becomes more complex, maintenance costs are increasing.
Another issue with the Active record is the binding between the object and the data table design. If you have to modify the database, modify the object model of the active record and all the related code at the same time.
The difference between a 3.Active record and a table pattern
Table pattern is usually the current three-layer framework in the popular datetable and Dateset as a carrier in the transfer of data in each layer, the Active record is the object model, generics (such as ilist<post>) as a carrier in the various layers of data transmission.
Second, Castle ActiveRecord introduction
Castle ActiveRecord is an implementation of the ActiveRecord pattern, Castle ActiveRecord relies on nhibernate to complete the actual image. Compared with pure ActiveRecord, Castle ActiveRecord has the following characteristics:
Agile development (which deals with mapping and inference as much as possible, so for your scenario, when something changes, you don't have to delve into the document or process a lot of XML documents)
A public method such as Create, Update, Save, delete is scheduled.
It is easy to implement such methods as Find, FindAll, Findbyname and so on.
Painting and transaction scope (Session and transaction scopes that abstracts the ISession and translates them to a more natural idiom)
With NHibernate, you have more tedious configuration work than complex mappings, while using ActiveRecord is a guarantee of boosting your productivity, and you don't have to worry about writing complicated mapping files, ActiveRecord encapsulates nhibernate operations, Using attributes instead of mapping files, ActiveRecord can give you a isession instance whenever you need it, providing a concise O/R mapping that will make it so simple and amazing to implement a persistent data layer!
Official website: http://www.castleproject.org/
Castle ActiveRecord Study (i)