CompositionAttribute Class

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

Indicates that a member represents an association that is part of a compositional hierarchy.

Inheritance Hierarchy


Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ServiceModel.DomainServices.Client (in System.ServiceModel.DomainServices.Client.dll)


<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field, AllowMultiple := False,  _
    Inherited := True)> _
Public NotInheritable Class CompositionAttribute _
    Inherits Attribute
Dim instance As CompositionAttribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false, 
    Inherited = true)]
public sealed class CompositionAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property|AttributeTargets::Field, AllowMultiple = false, 
    Inherited = true)]
public ref class CompositionAttribute sealed : public Attribute
[<AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false, 
    Inherited = true)>]
type CompositionAttribute =  
        inherit Attribute
public final class CompositionAttribute extends Attribute

The CompositionAttribute type exposes the following members.


  Name Description
Public method CompositionAttribute Initializes a new instance of the CompositionAttribute class.



  Name Description
Public property TypeId (Inherited from Attribute.)



  Name Description
Public method Equals (Inherited from Attribute.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Attribute.)
Public method GetType (Inherited from Object.)
Public method IsDefaultAttribute (Inherited from Attribute.)
Public method Match (Inherited from Attribute.)
Protected method MemberwiseClone (Inherited from Object.)
Public method ToString (Inherited from Object.)


Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method _Attribute.GetIDsOfNames (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfo (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfoCount (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.Invoke (Inherited from Attribute.)



You apply the CompositionAttribute to a property that represents an association between two entities that are conceptually part of a hierarchy, such as a SalesOrderHeader entity and a SalesOrderDetail entity. These related entities are known as a compositional hierarchy. After defining the compositional hierarchy between the classes, you can perform data modification operations on the entities as a single unit instead of as separate entities. This simplifies middle-tier logic because you can write application logic for the entire hierarchy instead of splitting that logic into each entity and attempting to coordinate that split logic during data operations. For more information, see Compositional Hierarchies.


The following example shows how to define a compositional relationship between SalesOrderHeader and SalesOrderDetail by using a metadata class.

<MetadataTypeAttribute(GetType(SalesOrderHeader.SalesOrderHeaderMetadata))>  _
Partial Public Class SalesOrderHeader

    Friend NotInheritable Class SalesOrderHeaderMetadata

        Private Sub New()
        End Sub

        <Include()> _
        <Composition()> _
        Public SalesOrderDetails As EntityCollection(Of SalesOrderDetail)

    End Class
End Class
public partial class SalesOrderHeader
    internal sealed class SalesOrderHeaderMetadata
        private SalesOrderHeaderMetadata()

        public EntitySet<SalesOrderDetail> SalesOrderDetails;


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also


System.ComponentModel.DataAnnotations Namespace