HasManyToAnyAttribute API Document
This attribute allows polymorphic association between classes that doesn't have a common root class. In require two columns that would tell it what is the type of the asssoicated entity, and what is the PK of that entity. For instnace, let assume that you have two classes (that implement a common interface, but have no base classs) called: - Back Account - Credit Card And you have a set of Payment methods, that can be either. You would define the mapping so:
[HasManyToAny(typeof(IPayment), "pay_id", "payments_table", typeof(int), "payment_type", "payment_method_id",
MetaType = typeof(int), RelationType = RelationType.Set)]
typeof(IPayement) - the common interface tha both classes implement, and the type of all the items in the set. "pay_id" - the column that hold the PK of this entity (the FK column) "payments_table" - the table that has the assoication information (in 1:M scenarios - usuaully the same table, in M:N scenarios the link table). typeof(int) - the type of id column "payment_type" - the column used to find out which class is represented by this row. "payment_method_id" - the column that holds the PK of the assoicated class (either CreditCard or BankAccount). MetaType = typeof(int) - the type of the meta column (payment_type) RelationType = RelationType.Set - specify that we use a set here
Constructors
HasManyToAnyAttribute(Type mapType, String keyColum, String table, Type idType, String typeColumn, String idColumn)
Initializes a new instance of the Castle.ActiveRecord.HasManyToAnyAttribute class.
| Parameter | Description |
|---|---|
| mapType | Type of the map. |
| keyColum | The key colum. |
| table | The table. |
| idType | Type of the id. |
| typeColumn | The type column. |
| idColumn | The id column. |
Properties
| Name | Type | Description |
|---|---|---|
| TypeColumn | String | Gets or sets the type column. |
| IdColumn | String | Gets or sets the id column. |
| MetaType | Type | Gets or sets the type of the meta column |
| IdType | Type | Gets or sets the type of the id column |
| ColumnKey | String | Gets or sets the key column name. |
| CompositeKeyColumnKeys | String[] | Gets or sets the names of the column in composite key scenarios. |
| RelationType | RelationType | Gets or sets the type of the relation. |
| MapType | Type | Gets or sets the type of the map. |
| Table | String | Gets or sets the table for this relation |
| Schema | String | Gets or sets the schema for this relation (dbo., etc) |
| Lazy | Boolean | Gets or sets a value indicating whether this Castle.ActiveRecord.RelationAttribute is lazy. |
| Inverse | Boolean | Gets or sets a value indicating whether this Castle.ActiveRecord.RelationAttribute is inverse. |
| Cascade | ManyRelationCascadeEnum | Gets or sets the cascade options for this Castle.ActiveRecord.RelationAttribute |
| OrderBy | String | Gets or sets the order by clause for this relation |
| Where | String | Gets or sets the where clause for this relation |
| Sort | String | Only used with sets |
| Index | String | Only used with maps or list |
| IndexType | String | Only used with maps |
| Element | String | Use for simple types. |
| Cache | CacheEnum | Gets or sets the cache strategy to use for this property |
| 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. |