This attribute is used to create <any/> assoication, a polymorphic assoication to classes that
do not share a common base class.
Namespace: Castle.ActiveRecord
Examples
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:
CopyC#
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.
[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 { ... } } |
Assembly: Castle.ActiveRecord (in Castle.ActiveRecord.dll)
Version: 1.0.3.0
Syntax
| C# |
|---|
[SerializableAttribute] [AttributeUsageAttribute(AttributeTargets.Property, AllowMultiple = false)] public class AnyAttribute : WithAccessAttribute |
Remarks
This is supplied for advanced sceanrios.
Inheritance Hierarchy
System..::Object
System..::Attribute
Castle.ActiveRecord..::WithAccessAttribute
Castle.ActiveRecord..::AnyAttribute
System..::Attribute
Castle.ActiveRecord..::WithAccessAttribute
Castle.ActiveRecord..::AnyAttribute
See Also
AnyAttribute Members
Castle.ActiveRecord Namespace