Compartilhar via


LoadBehavior Enumeration

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

Specifies control identity cache behavior when loading entities.

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

Syntax

'Declaration
Public Enumeration LoadBehavior
'Usage
Dim instance As LoadBehavior
public enum LoadBehavior
public enum class LoadBehavior
type LoadBehavior
public enum LoadBehavior

Members

Member name Description
MergeIntoCurrent Values from the newly read instance are merged into the cached instance for property values that are unmodified. No changes are lost in this merge.
KeepCurrent The cached instance is not changed and the newly read instance is discarded.
RefreshCurrent All members of the cached instance are overwritten with current values from the newly read instance, regardless of whether they have been modified. In addition, the original state of the entity is also set to the newly read instance.

Remarks

Each option specifies the merge behavior when an entity that has been previously read and cached is read again.

Examples

Public Function MainPage()
    InitializeComponent()

    ' Create an EntityQuery of type Customer
    Dim query As EntityQuery(Of Customer) = _
        From c In _customerContext.GetCustomersQuery() _
        Where (c.Phone.StartsWith("583")())() _
        Order By (c.LastName) _
        Select c()

    ' Create and execute a LoadOperation of type Customer and load 'query'
    ' LoadBehavior is set to merge this query into the current cache
    Dim loadOp As LoadOperation = Me._customerContext.Load(query, LoadBehavior.MergeIntoCurrent, False)

    ' Create a new DomainOperationException for a Validation Error
    Dim opEx As DomainOperationException = New DomainOperationException( _
                                            "Validation Error", _
                                            OperationErrorStatus.ValidationError, _
                                            9466)
    ' Check if there are any ValidationErrors when loadOp was executed
    ' Then throw the DomainOperationException opEx
    If loadOp.ValidationErrors <> Empty Then
        Throw opEx
    End If

    ' Populate the CustomerGrid with the Entities in loadOp
    CustomerGrid.ItemsSource = loadOp.Entities
// Create an EntityQuery of type Customer
EntityQuery<Customer> query =
    from c in _customerContext.GetCustomersQuery()
    where c.Phone.StartsWith("583")
    orderby c.LastName
    select c;

// Create and execute a LoadOperation of type Customer and load 'query'
// LoadBehavior is set to merge this query into the current cache
LoadOperation<Customer> loadOp = this._customerContext.Load(query, LoadBehavior.MergeIntoCurrent, false);

// Create a new DomainOperationException for a Validation Error
DomainOperationException opEx = new DomainOperationException(
    "Validation Error",
    OperationErrorStatus.ValidationFailed,
    0x000024FA);

// Check if there are any ValidationErrors when loadOp was executed
// Then throw the DomainOperationException opEx
if (loadOp.ValidationErrors != null)
{
    throw opEx;
}

// Populate the CustomerGrid with the Entities in loadOp
CustomerGrid.ItemsSource = loadOp.Entities;

See Also

Reference

System.ServiceModel.DomainServices.Client Namespace