EntityCollection(Of TEntity) Class

WCF RIA Services

[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.]

Represents a collection of associated entities.

System.Object
  System.ServiceModel.DomainServices.Client.EntityCollection(Of TEntity)

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

'Declaration
Public NotInheritable Class EntityCollection(Of TEntity As Entity) _
	Implements IEnumerable(Of TEntity), IEnumerable, INotifyCollectionChanged,  _
	INotifyPropertyChanged, ICollectionViewFactory
'Usage
Dim instance As EntityCollection(Of TEntity)

Type Parameters

TEntity

The type of Entity in the collection.

The EntityCollection(Of TEntity) type exposes the following members.

  NameDescription
Public methodEntityCollection(Of TEntity)(Entity, String, Func(Of TEntity, Boolean))Initializes a new instance of the EntityCollection(Of TEntity) class with the specified parent, name of the collection on the parent, and filter function.
Public methodEntityCollection(Of TEntity)(Entity, String, Func(Of TEntity, Boolean), Action(Of TEntity), Action(Of TEntity))Initializes a new instance of the EntityCollection(Of TEntity) class with the specified parent, name of the collection on the parent, and functions for filtering, attaching, and detaching.
Top

  NameDescription
Public propertyCountGets the current count of entities in this collection.
Top

  NameDescription
Public methodAddAdds the specified entity to this collection.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetEnumeratorReturns an enumerator for this collection.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodRemoveRemoves the specified entity from this collection.
Public methodToStringReturns a textual representation of the collection. (Overrides Object.ToString.)
Top

  NameDescription
Public eventEntityAddedRaised when an Entity is added to this collection.
Public eventEntityRemovedRaised when an Entity is removed from this collection.
Top

  NameDescription
Explicit interface implemetationPrivate eventINotifyCollectionChanged.CollectionChangedRaised when the contents of the collection changes.
Explicit interface implemetationPrivate methodICollectionViewFactory.CreateViewReturns a custom view for specialized sorting, filtering, grouping, and currency.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an enumerator for this collection.
Explicit interface implemetationPrivate eventINotifyPropertyChanged.PropertyChangedRaised when a property on this collection changes.
Top

' <summary>
' Gets the collection of associated <see cref="Employee"/> entity instances.
' </summary>
<Association("Employee_Employee", "EmployeeID", "ManagerID")>
<XmlIgnore()>
Public ReadOnly Property Employee0 As EntityCollection(Of Employee)
    Get
        If Me._employee0 = Nothing Then
            Me._employee0 = New EntityCollection(Of Employee)(Me, "Employee0", Me.FilterEmployee0);
        End If
    End Get
End Property

<Association("Employee_Employee", "EmployeeID", "ManagerID")>
<XmlIgnore()>
Public ReadOnly Property Employee1 As EntityCollection(Of Employee)
    Get
        If Me._employee1 = Nothing Then
            Me._employee1 = New EntityCollection(Of Employee)(Me, "Employee1", Me.FilterEmployee1, Me.AttachEmployee1, Me.DetachEmployee1);
        End If
    End Get
End Property

' <summary>
' Gets or sets the associated <see cref="Employee"/> entity.
' </summary>
<Association("Employee_Employee", "ManagerID", "EmployeeID", IsForeignKey = True)>
<XmlIgnore()>
Public Property Employee2 As Employee
    Get
        If Me._employee2 = Nothing Then
            Me._employee2 = New EntityRef(Of Employee)(Me, "Employee2", Me.FilterEmployee2)
        End If
    End Get
    Set(ByVal value As Employee)
        Dim previous As Employee = Me.Employee2

        If previous = Me.Employee2 Then
            Me.ValidateProperty("Employee2", value)
            ' EntityCollection.Remove()
            If previous <> Value Then
                Me._employee2.Entity = Nothing
                previous.Employee1.Remove(Me)
                Me.Employee1.EntityRemoved += New EventHandler(Of EntityCollectionChangedEventArgs(Of Employee))(Employee1_EntityRemoved)
            End If
            If Value <> Nothing Then
                Me.ManagerID = value.EmployeeID
            End If

            Me._employee2.Entity = value
            ' EntityCollection.Add()
            If value <> Nothing Then
                value.Employee1.Add(Me)
                Me.Employee1.EntityAdded += New EventHandler(Of EntityCollectionChangedEventArgs(Of Employee))(Employee1_EntityAdded)
            End If

            Me.RaisePropertyChanged("Employee2")
        End If
    End Set
End Property

Public Property Employee1_EntityAdded As EventHandler(Of EntityCollectionChangedEventArgs(Of Employee))
    Set(ByVal value As EventHandler(Of EntityCollectionChangedEventArgs(Of Employee)))
        Me._count = Me.Employee1.Count
    End Set
End Property

Public Property Employee1_EntityRemoved As EventHandler(Of EntityCollectionChangedEventArgs(Of Employee))
    Set(ByVal value As EventHandler(Of EntityCollectionChangedEventArgs(Of Employee)))
        Me._count = Me.Employee1.Count
    End Set
End Property

Public ReadOnly Property Employee1Enumerator As IEnumerator(Of Employee)
    Get
        Return this._employee1Enumerator
    End Get
End Property

Private Function AttachEmployee0(ByVal entity As Employee)
    entity.Employee2 = Me
End Function

Private Function AttachEmployee1(ByVal entity As Employee)
    entity.Employee2 = Me
End Function

Private Function DetachEmployee0(ByVal entity As Employee)
    entity.Employee2 = Nothing
End Function

Private Function DetachEmployee1(ByVal entity As Employee)
    entity.Employee2 = Nothing
End Function

Private Function FilterEmployee0(ByVal entity As Employee) As Boolean
    Return (entity.ManagerID = Me.EmployeeID)
End Function

Private Function FilterEmployee1(ByVal entity As Employee) As Boolean
    Return (entity.ManagerID = Me.EmployeeID)
End Function

Private Function FilterEmployee2(ByVal entity As Employee) As Boolean
    Return (entity.ManagerID = Me.EmployeeID)
End Function



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