Export (0) Print
Expand All

LinqToEntitiesDomainService(Of TContext) 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.]

Provides a base class for domain services operating on LINQ to Entities data models.

    System.ServiceModel.DomainServices.EntityFramework.LinqToEntitiesDomainService(Of TContext)

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

<LinqToEntitiesDomainServiceDescriptionProviderAttribute> _
Public MustInherit Class LinqToEntitiesDomainService(Of TContext As {New, ObjectContext}) _
	Inherits DomainService
Dim instance As LinqToEntitiesDomainService(Of TContext)

Type Parameters


The type of the LINQ to Entities ObjectContext.

The LinqToEntitiesDomainService(Of TContext) type exposes the following members.

Protected methodLinqToEntitiesDomainService(Of TContext)Initializes a new instance of the LinqToEntitiesDomainService(Of TContext) class.

Protected propertyAuthorizationContextGets or sets the optional template AuthorizationContext to use for IsAuthorized. (Inherited from DomainService.)
Protected propertyChangeSetGets the current ChangeSet. (Inherited from DomainService.)
Protected propertyObjectContextGets the ObjectContext for this LinqToEntitiesDomainService(Of TContext).
Protected propertyServiceContextGets the active DomainServiceContext for this DomainService. (Inherited from DomainService.)
Protected propertyServiceDescriptionGets the DomainServiceDescription for this DomainService. (Inherited from DomainService.)
Protected propertyValidationContextGets or sets the optional ValidationContext to use for all validation operations invoked by the DomainService. (Inherited from DomainService.)

Protected methodAuthorizeChangeSetReturns a value that indicates the whether the user is authorized to submit the specified ChangeSet. (Inherited from DomainService.)
Protected methodCount(Of T)(IQueryable(Of T))Returns the number of rows in the specified IQueryable object. (Overrides DomainService.Count(Of T)(IQueryable(Of T)).)
Protected methodCount(Of T)(IQueryable(Of T))Returns the number of rows in an IQueryable. (Inherited from DomainService.)
Protected methodCreateObjectContextCreates and returns the ObjectContext instance that will be used by this provider.
Public methodDisposeReleases all resources used by the current instance of the DomainService class. (Inherited from DomainService.)
Protected methodDispose(Boolean)Releases all resources used by the LinqToEntitiesDomainService(Of TContext). (Overrides DomainService.Dispose(Boolean).)
Public methodEquals (Inherited from Object.)
Protected methodExecuteChangeSetInvokes the DomainOperationEntry for each operation in the ChangeSet. (Inherited from DomainService.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodInitializeInitializes the domain service. (Overrides DomainService.Initialize(DomainServiceContext).)
Public methodInvokeInvokes the specified operation. (Inherited from DomainService.)
Public methodIsAuthorizedRequests authorization for the specified DomainOperationEntry. (Inherited from DomainService.)
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnErrorCalled whenever an unrecoverable error occurs during the processing of a DomainService operation. (Inherited from DomainService.)
Protected methodPersistChangeSetFinalizes changes after all the operations in the ChangeSet have been invoked. (Overrides DomainService.PersistChangeSet.)
Public methodQueryPerforms the query operation indicated by the specified QueryDescription. (Inherited from DomainService.)
Protected methodResolveConflictsResolves the conflicts when the submit fails due to optimistic concurrency conflicts.
Public methodSubmitPerforms the operations indicated by the specified ChangeSet by invoking each of the corresponding domain operations. (Inherited from DomainService.)
Public methodToString (Inherited from Object.)
Protected methodValidateChangeSetValidates the whole ChangeSet before calling ExecuteChangeSet. (Inherited from DomainService.)

You create domain service classes that derive from the LinqToEntitiesDomainService(Of TContext) class when you expose LINQ to Entities types. When you use the Add New Domain Service Class dialog box to create a domain service that exposes LINQ to Entities types, the dialog box automatically creates a class that derives from LinqToEntitiesDomainService(Of TContext). The class is created with methods that provide a starting point for implementing business logic in your application. A query method is included in the class. If you select the Enable Edit check box, insert, update, and delete methods are included. You should add methods or customize the existing methods to meet the requirement of your application.

You use the ObjectContext property to access the object that facilitates interacting with entity data objects.

The following example shows a domain service that derives from LinqToEntitiesDomainService(Of TContext). It contains methods for querying, updating, and deleting data.

<EnableClientAccess()>  _
Public Class OrderDomainService
    Inherits LinqToEntitiesDomainService(Of AdventureWorksLT_DataEntities)

    Public Function GetSalesOrders() As IQueryable(Of SalesOrderHeader)
        Return Me.ObjectContext.SalesOrderHeaders.Include("SalesOrderDetails")
    End Function

    Public Sub UpdateSalesOrder(ByVal currentSalesOrderHeader As SalesOrderHeader)
        Dim originalOrder As SalesOrderHeader = Me.ChangeSet.GetOriginal(currentSalesOrderHeader)

        If (currentSalesOrderHeader.EntityState = EntityState.Detached) Then
            If (IsNothing(originalOrder)) Then
                Me.ObjectContext.AttachAsModified(currentSalesOrderHeader, Me.ChangeSet.GetOriginal(currentSalesOrderHeader))
            End If
        End If

        For Each detail As SalesOrderDetail In Me.ChangeSet.GetAssociatedChanges(currentSalesOrderHeader, Function(o) o.SalesOrderDetails)
            Dim op As ChangeOperation = Me.ChangeSet.GetChangeOperation(detail)

            Select Case op
                Case ChangeOperation.Insert
                    If ((detail.EntityState = EntityState.Added) _
                    = False) Then
                        If ((detail.EntityState = EntityState.Detached) _
                                    = False) Then
                            Me.ObjectContext.ObjectStateManager.ChangeObjectState(detail, EntityState.Added)
                        End If
                    End If
                Case ChangeOperation.Update
                    Me.ObjectContext.AttachAsModified(detail, Me.ChangeSet.GetOriginal(detail))
                Case ChangeOperation.Delete
                    If (detail.EntityState = EntityState.Detached) Then
                    End If
            End Select
    End Sub

    Public Sub DeleteSalesOrder(ByVal salesOrderHeader As SalesOrderHeader)
        If (salesOrderHeader.EntityState = EntityState.Detached) Then
        End If

        Select Case salesOrderHeader.Status
            Case 1 ' in process
            Case 2, 3, 4 ' approved, backordered, rejected
                salesOrderHeader.Status = 6
            Case 5 ' shipped
                Throw New ValidationException("The order has been shipped and cannot be deleted.")
        End Select

    End Sub
End Class

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