Compartilhar via


EntityRef<TEntity> 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.]

Represents a reference to an associated entity.

Inheritance Hierarchy

System.Object
  System.ServiceModel.DomainServices.Client.EntityRef<TEntity>

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

Syntax

'Declaration
Public NotInheritable Class EntityRef(Of TEntity As Entity)
'Usage
Dim instance As EntityRef(Of TEntity)
public sealed class EntityRef<TEntity>
where TEntity : Entity
generic<typename TEntity>
where TEntity : Entity
public ref class EntityRef sealed
[<SealedAttribute>]
type EntityRef<'TEntity when 'TEntity : Entity> =  class end
JScript does not support generic types and methods.

Type Parameters

  • TEntity
    The type of the associated Entity.

The EntityRef<TEntity> type exposes the following members.

Constructors

  Name Description
Public method EntityRef<TEntity> Initializes an instance of the EntityRef<TEntity> class.

Top

Properties

  Name Description
Public property Entity Gets or sets the associated Entity.

Top

Methods

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

Top

Examples

<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 Employee Employee2
{
    get
    {
        if ((this._employee2 == null))
        {
            // Set this._employee2 equal to a new EntityRef of Type Employee.
            this._employee2 = new EntityRef<Employee>(this, "Employee2", this.FilterEmployee2);
        }
        return this._employee2.Entity;
    }
    set
    {
        Employee previous = this.Employee2;
        if ((previous != value))
        {
            this.ValidateProperty("Employee2", value);
            // EntityCollection.Remove()
            if ((previous != null))
            {
                this._employee2.Entity = null;
                previous.Employee1.Remove(this);
                this.Employee1.EntityRemoved += new EventHandler<EntityCollectionChangedEventArgs<Employee>>(Employee1_EntityRemoved);
            }
            if ((value != null))
            {
                this.ManagerID = value.EmployeeID;
            }
            else
            {
                this.ManagerID = default(Nullable<int>);
            }
            this._employee2.Entity = value;
            // EntityCollection.Add()
            if ((value != null))
            {
                value.Employee1.Add(this);
                this.Employee1.EntityAdded += new EventHandler<EntityCollectionChangedEventArgs<Employee>>(Employee1_EntityAdded);

            }
            this.RaisePropertyChanged("Employee2");
        }
    }
}

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

Reference

System.ServiceModel.DomainServices.Client Namespace