Table of contents
- 1 Constructors
- 2 Methods
- 2.1 Refresh()
- 2.2 Delete()
- 2.3 Update()
- 2.4 Create()
- 2.5 Save()
- 2.6 OnLoad(Object id)
- 2.7 OnDelete()
- 2.8 OnUpdate()
- 2.9 OnSave()
- 2.10 FindDirty(Object id, IDictionary previousState, IDictionary currentState, IType[] types) : Int32[]
- 2.11 IsUnsaved() : Object
- 2.12 PostFlush()
- 2.13 PreFlush()
- 2.14 BeforeDelete(IDictionary adapter)
- 2.15 BeforeLoad(IDictionary adapter) : Boolean
- 2.16 BeforeSave(IDictionary state) : Boolean
- 2.17 ToString() : String
- 2.18 Create(Object instance)
- 2.19 Delete(Object instance)
- 2.20 Refresh(Object instance)
- 2.21 DeleteAll(Type type)
- 2.22 DeleteAll(Type type, String where)
- 2.23 DeleteAll(Type targetType, IEnumerable pkValues) : Int32
- 2.24 Update(Object instance)
- 2.25 Save(Object instance)
- 2.26 Execute(Type targetType, NHibernateDelegate call, Object instance) : Object
- 2.27 EnumerateQuery(IActiveRecordQuery query) : IEnumerable
- 2.28 ExecuteQuery(IActiveRecordQuery query) : Object
- 2.29 CountAll(Type targetType) : Int32
- 2.30 CountAll(Type targetType, String filter, Object[] args) : Int32
- 2.31 Exists(Type targetType) : Boolean
- 2.32 Exists(Type targetType, String filter, Object[] args) : Boolean
- 2.33 Exists(Type targetType, Object id) : Boolean
- 2.34 FindAll(Type targetType) : Array
- 2.35 FindAll(Type targetType, Order[] orders, ICriterion[] criterias) : Array
- 2.36 FindAll(Type targetType, ICriterion[] criterias) : Array
- 2.37 FindAllByProperty(Type targetType, String property, Object value) : Array
- 2.38 FindAllByProperty(Type targetType, String orderByColumn, String property, Object value) : Array
- 2.39 FindByPrimaryKey(Type targetType, Object id) : Object
- 2.40 FindByPrimaryKey(Type targetType, Object id, Boolean throwOnNotFound) : Object
- 2.41 FindFirst(Type targetType, Order[] orders, ICriterion[] criterias) : Object
- 2.42 FindFirst(Type targetType, ICriterion[] criterias) : Object
- 2.43 FindOne(Type targetType, ICriterion[] criterias) : Object
- 2.44 SlicedFindAll(Type targetType, Int32 firstResult, Int32 maxResults, Order[] orders, ICriterion[] criterias) : Array
- 2.45 SlicedFindAll(Type targetType, Int32 firstResult, Int32 maxResults, ICriterion[] criterias) : Array
- 2.46 Execute(NHibernateDelegate call) : Object
ActiveRecordBase API Document
Base class for all ActiveRecord classes. Implements all the functionality to simplify the code on the subclasses.
Constructors
ActiveRecordBase()
Constructs an ActiveRecordBase subclass.
Methods
Refresh()
Refresh the instance from the database.
Delete()
Deletes the instance from the database.
Update()
Persists the modification on the instance state to the database.
Create()
Creates (Saves) a new instance to the database.
Save()
Saves the instance information to the database. May Create or Update the instance depending on whether it has a valid ID.
OnLoad(Object id)
Lifecycle method invoked during Load of the entity
| Parameter | Description |
|---|---|
| id | Missing documentation |
OnDelete()
Lifecycle method invoked during Delete of the entity
OnUpdate()
Lifecycle method invoked during Update of the entity
OnSave()
Lifecycle method invoked during Save of the entity
FindDirty(Object id, IDictionary previousState, IDictionary currentState, IType[] types) : Int32[]
Called from Flush(). The return value determines whether the entity is updated
| Parameter | Description |
|---|---|
| id | Missing documentation |
| previousState | Missing documentation |
| currentState | Missing documentation |
| types | Missing documentation |
IsUnsaved() : Object
Called when a transient entity is passed to SaveOrUpdate.
PostFlush()
Called after a flush that actually ends in execution of the SQL statements required to synchronize in-memory state with the database.
PreFlush()
Called before a flush
BeforeDelete(IDictionary adapter)
Hook to perform additional tasks before removing the object instance representation from the database.
| Parameter | Description |
|---|---|
| adapter | Missing documentation |
BeforeLoad(IDictionary adapter) : Boolean
Hook to transform the read data from the database before populating the object instance
| Parameter | Description |
|---|---|
| adapter | Missing documentation |
BeforeSave(IDictionary state) : Boolean
Hook to change the object state before saving it.
| Parameter | Description |
|---|---|
| state | Missing documentation |
ToString() : String
Missing summary
Create(Object instance)
Creates (Saves) a new instance to the database.
| Parameter | Description |
|---|---|
| instance | The ActiveRecord instance to be created on the database |
Delete(Object instance)
Deletes the instance from the database.
| Parameter | Description |
|---|---|
| instance | The ActiveRecord instance to be deleted |
Refresh(Object instance)
Refresh the instance from the database.
| Parameter | Description |
|---|---|
| instance | The ActiveRecord instance to be reloaded |
DeleteAll(Type type)
Deletes all rows for the specified ActiveRecord type
This method is usually useful for test cases.
| Parameter | Description |
|---|---|
| type | ActiveRecord type on which the rows on the database should be deleted |
DeleteAll(Type type, String where)
Deletes all rows for the specified ActiveRecord type that matches the supplied HQL condition
This method is usually useful for test cases.
| Parameter | Description |
|---|---|
| type | ActiveRecord type on which the rows on the database should be deleted |
| where | HQL condition to select the rows to be deleted |
DeleteAll(Type targetType, IEnumerable pkValues) : Int32
Deletes all targetType objects, based on the primary keys supplied on pkValues.
| Parameter | Description |
|---|---|
| targetType | The target ActiveRecord type |
| pkValues | A list of primary keys |
Update(Object instance)
Persists the modification on the instance state to the database.
| Parameter | Description |
|---|---|
| instance | The ActiveRecord instance to be updated on the database |
Save(Object instance)
Saves the instance to the database. If the primary key is unitialized it creates the instance on the database. Otherwise it updates it.
If the primary key is assigned, then you must invoke Castle.ActiveRecord.ActiveRecordBase.Create or Castle.ActiveRecord.ActiveRecordBase.Update instead.
| Parameter | Description |
|---|---|
| instance | The ActiveRecord instance to be saved |
Execute(Type targetType, NHibernateDelegate call, Object instance) : Object
Invokes the specified delegate passing a valid NHibernate session. Used for custom NHibernate queries.
| Parameter | Description |
|---|---|
| targetType | The target ActiveRecordType |
| call | The delegate instance |
| instance | The ActiveRecord instance |
EnumerateQuery(IActiveRecordQuery query) : IEnumerable
Missing summary
| Parameter | Description |
|---|---|
| query | Missing documentation |
ExecuteQuery(IActiveRecordQuery query) : Object
Missing summary
| Parameter | Description |
|---|---|
| query | Missing documentation |
CountAll(Type targetType) : Int32
Returns the number of records of the specified type in the database
Example
[ActiveRecord] public class User : ActiveRecordBase { ... public static int CountAllUsers() { return CountAll(typeof(User)); } }
| Parameter | Description |
|---|---|
| targetType | Type of the target. |
CountAll(Type targetType, String filter, Object[] args) : Int32
Returns the number of records of the specified type in the database
Example
[ActiveRecord] public class User : ActiveRecordBase { ... public static int CountAllUsersLocked() { return CountAll(typeof(User), "IsLocked = ?", true); } }
| Parameter | Description |
|---|---|
| targetType | Type of the target. |
| filter | A sql where string i.e. Person=? and DOB > ? |
| args | Positional parameters for the filter string |
Exists(Type targetType) : Boolean
Check if there is any records in the db for the target type
| Parameter | Description |
|---|---|
| targetType | Type of the target. |
Exists(Type targetType, String filter, Object[] args) : Boolean
Check if there is any records in the db for the target type
| Parameter | Description |
|---|---|
| targetType | Type of the target. |
| filter | A sql where string i.e. Person=? and DOB > ? |
| args | Positional parameters for the filter string |
Exists(Type targetType, Object id) : Boolean
Check if the id exists in the database.
| Parameter | Description |
|---|---|
| targetType | Type of the target. |
| id | The id to check on |
FindAll(Type targetType) : Array
Returns all instances found for the specified type.
| Parameter | Description |
|---|---|
| targetType |
FindAll(Type targetType, Order[] orders, ICriterion[] criterias) : Array
Returns all instances found for the specified type using sort orders and criterias.
| Parameter | Description |
|---|---|
| targetType | |
| orders | |
| criterias |
FindAll(Type targetType, ICriterion[] criterias) : Array
Returns all instances found for the specified type using criterias.
| Parameter | Description |
|---|---|
| targetType | |
| criterias |
FindAllByProperty(Type targetType, String property, Object value) : Array
Finds records based on a property value - automatically converts null values to IS NULL style queries.
| Parameter | Description |
|---|---|
| targetType | The target type |
| property | A property name (not a column name) |
| value | The value to be equals to |
FindAllByProperty(Type targetType, String orderByColumn, String property, Object value) : Array
Finds records based on a property value - automatically converts null values to IS NULL style queries.
| Parameter | Description |
|---|---|
| targetType | The target type |
| orderByColumn | The column name to be ordered ASC |
| property | A property name (not a column name) |
| value | The value to be equals to |
FindByPrimaryKey(Type targetType, Object id) : Object
Finds an object instance by an unique ID
| Parameter | Description |
|---|---|
| targetType | The AR subclass type |
| id | ID value |
FindByPrimaryKey(Type targetType, Object id, Boolean throwOnNotFound) : Object
Finds an object instance by an unique ID
| Parameter | Description |
|---|---|
| targetType | The AR subclass type |
| id | ID value |
| throwOnNotFound | true if you want to catch an exception if the object is not found |
FindFirst(Type targetType, Order[] orders, ICriterion[] criterias) : Object
Searches and returns the first row.
| Parameter | Description |
|---|---|
| targetType | The target type |
| orders | The sort order - used to determine which record is the first one |
| criterias | The criteria expression |
FindFirst(Type targetType, ICriterion[] criterias) : Object
Searches and returns the first row.
| Parameter | Description |
|---|---|
| targetType | The target type |
| criterias | The criteria expression |
FindOne(Type targetType, ICriterion[] criterias) : Object
Searches and returns a row. If more than one is found, throws Castle.ActiveRecord.Framework.ActiveRecordException
| Parameter | Description |
|---|---|
| targetType | The target type |
| criterias | The criteria expression |
SlicedFindAll(Type targetType, Int32 firstResult, Int32 maxResults, Order[] orders, ICriterion[] criterias) : Array
Returns a portion of the query results (sliced)
| Parameter | Description |
|---|---|
| targetType | Missing documentation |
| firstResult | Missing documentation |
| maxResults | Missing documentation |
| orders | Missing documentation |
| criterias | Missing documentation |
SlicedFindAll(Type targetType, Int32 firstResult, Int32 maxResults, ICriterion[] criterias) : Array
Returns a portion of the query results (sliced)
| Parameter | Description |
|---|---|
| targetType | Missing documentation |
| firstResult | Missing documentation |
| maxResults | Missing documentation |
| criterias | Missing documentation |
Execute(NHibernateDelegate call) : Object
Invokes the specified delegate passing a valid NHibernate session. Used for custom NHibernate queries.
| Parameter | Description |
|---|---|
| call | The delegate instance |