Home

Castle Stronghold

AnyAttribute API Document

This attribute is used to create assoication, a polymorphic assoication to classes that do not share a common base class.

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.

Quick Note

This is supplied for advanced sceanrios.

Constructors

AnyAttribute(Type idType)

Initializes a new instance of the Castle.ActiveRecord.AnyAttribute class.

ParameterDescription
idType Type of the id.

Properties

NameTypeDescription
IdTypeType Gets or sets the type of the id.
MetaTypeType Gets or sets the type of the meta column
CascadeCascadeEnum Gets or sets the cascade options
TypeColumnString Gets or sets the type column name
IdColumnString Gets or sets the id column name
IndexString Gets or sets the index column name
InsertBoolean Gets or sets a value indicating whether the column should be inserted when inserting.
UpdateBoolean Gets or sets a value indicating whether the column should be is updated when updating.
AccessPropertyAccess Gets or sets the access strategy for this property
CustomAccessString Gets or sets the custom access strategy
AccessStringString Gets the access strategy string for NHibernate's mapping.

Google
Search WWW Search castleproject.org