Table of contents
AnyAttribute API Document
This attribute is used to create Assuming we have two classes that implement IPayment, CreditCard and BankAccount, and we want a property that can point ot either one of them. We can map it like this:
[Any(typeof (long), MetaType=typeof (string),
TypeColumn="BILLING_DETAILS_TYPE",
IdColumn="BILLING_DETAILS_ID",
Cascade=CascadeEnum.SaveUpdate)]
[Any.MetaValue("CREDIT_CARD", typeof (CreditCard))]
[Any.MetaValue("BANK_ACCOUNT", typeof (BankAccount))]
public IPayment Payment { get { ... } set { ... } }
The [Any] attribute specify that the id type is long, that the meta type (the type that specify the type of the class) is string. The TypeColumn = "BILLING_DETAILS_TYPE" means that Active Record will look in this column to figure out what the type of the associated entity is. The IdColumn = "BILLING_DETAILS_ID" means that Active Record will use this column in conjuction with the type of the entity to find the relevant entity. This is the id of the associated entity (which can point to either back account or credit card). Cascade has the usual semantics. [Any.MetaValue("CREDIT_CARD", typeof (CreditCard))] - means that when Active Record encounters a "CREDIT_CARD" value in the "BILLING_DETAILS_TYPE", is assumes that the id in the "BILLING_DETAILS_ID" is the id of a CreditCard entity. [Any.MetaValue("BANK_ACCOUNT", typeof (BankAccount))] - same, just for "BANK_ACCOUNT" meaning that the id in "BILLING_DETAILS_ID" is an id of a bank account.
This is supplied for advanced sceanrios.
Constructors
AnyAttribute(Type idType)
Initializes a new instance of the Castle.ActiveRecord.AnyAttribute class.
| Parameter | Description |
|---|---|
| idType | Type of the id. |
Properties
| Name | Type | Description |
|---|---|---|
| IdType | Type | Gets or sets the type of the id. |
| MetaType | Type | Gets or sets the type of the meta column |
| Cascade | CascadeEnum | Gets or sets the cascade options |
| TypeColumn | String | Gets or sets the type column name |
| IdColumn | String | Gets or sets the id column name |
| Index | String | Gets or sets the index column name |
| Insert | Boolean | Gets or sets a value indicating whether the column should be inserted when inserting. |
| Update | Boolean | Gets or sets a value indicating whether the column should be is updated when updating. |
| Access | PropertyAccess | Gets or sets the access strategy for this property |
| CustomAccess | String | Gets or sets the custom access strategy |
| AccessString | String | Gets the access strategy string for NHibernate's mapping. |