May be applied to an entity that extends a mapped superclass to override a relationship mapping defined by the mapped superclass. If not specified, the association is mapped the same as in the original mapping. When used to override a mapping defined by a mapped superclass, AssociationOverride is applied to the entity class.
May be used to override a relationship mapping from an embeddable within an entity to another entity when the embeddable is on the owning side of the relationship. When used to override a relationship mapping defined by an embeddable class (including an embeddable class embedded within another embeddable class), AssociationOverride is applied to the field or property containing the embeddable.
When AssociationOverride is used to override a relationship mapping from an embeddable class, the name element specifies the referencing relationship field or property within the embeddable class. To override mappings at multiple levels of embedding, a dot (".") notation syntax must be used in the name element to indicate an attribute within an embedded attribute. The value of each identifier used with the dot notation is the name of the respective embedded field or property.
When AssociationOverride is applied to override the mappings of an embeddable class used as a map value, "value." must be used to prefix the name of the attribute within the embeddable class that is being overridden in order to specify it as part of the map value.
If the relationship mapping is a foreign key mapping, the joinColumn elements are used. If the relationship mapping uses a join table, the joinTable element must be specified to override the mapping of the join table and/or its join columns.
Examples
Example 1: Overriding the mapping of a relationship defined by a mapped superclass [MappedSuperclass] public class Employee { ... [ManyToOne] protected Address address; ... } [Entity] [AssociationOverride(Name="address")] [JoinColumn(AttibuteRef="address",Name="ADDR_ID")] // address field mapping overridden to ADDR_ID foreign key public class PartTimeEmployee extends Employee { ... }
Examples
Example 2: Overriding the mapping for phoneNumbers defined in the ContactInfo class [Entity] public class Employee { [Id] public virtual int id { get; set; } [AssociationOverride(Name="phoneNumbers")] [JoinTable(Name="EMPPHONES", AssociationOverrideRef="phoneNumbers")] [JoinColumn(AttributeRef="EMPPHONES", Name="EMP")] [JoinColumn(AttributeRef="EMPPHONES",Name="PHONE", Inverse=true)] [Embedded] public virtual ContactInfo contactInfo { get; set; } } [Embeddable] public class ContactInfo { [ManyToOne] Address address; // Unidirectional [ManyToMany(TargetEntity=typeof(PhoneNumber))] public virtual IList phoneNumbers { get; set; } } [Entity] public class PhoneNumber { [Id] public virtual int number { get; set; } [ManyToMany(MappedBy="contactInfo.phoneNumbers")] public virtual Collection<Employee> employees { get; set; } }
Assembly: NPersistence (in NPersistence.dll) Version: 2.0.0.0 (2.0.0.0)
Syntax
C# |
public sealed class AssociationOverride : Attribute
Members
All Members | Constructors | Fields |
Public Protected | Instance Static | Declared Inherited | XNA Framework Only .NET Compact Framework Only |
Member | Description | |
---|---|---|
AssociationOverride()()()() | Initializes a new instance of the AssociationOverride class | |
Name | (Required) The name of the relationship property whose mapping is
being overridden if property-based access is being used,
or the name of the relationship field if field-based access is used.
|
Inheritance Hierarchy
System..::..Attribute
NPersistence..::..AssociationOverride