Споделяне чрез


OrganizationServiceContext Class

 

Applies To: Dynamics CRM 2015

Represents the runtime context of the data service that is used to track Microsoft Dynamics CRM entities and that sends and receives entities from the server.

Namespace:   Microsoft.Xrm.Sdk.Client
Assembly:  Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)

Inheritance Hierarchy

System.Object
  Microsoft.Xrm.Sdk.Client.OrganizationServiceContext

Syntax

public class OrganizationServiceContext : IDisposable
public ref class OrganizationServiceContext : IDisposable
type OrganizationServiceContext = 
    class
        interface IDisposable
    end
Public Class OrganizationServiceContext
    Implements IDisposable

Constructors

Name Description
System_CAPS_pubmethod OrganizationServiceContext(IOrganizationService)

Creates a new instance of the OrganizationServiceContext class.

Properties

Name Description
System_CAPS_pubproperty ConcurrencyBehavior

Specifies the type of optimistic concurrency behavior that should be performed by the Web service when processing this request.

System_CAPS_pubproperty MergeOption

Gets or sets the synchronization option for receiving entities from the Web service.

System_CAPS_protproperty QueryProvider

Gets the query provider.

System_CAPS_pubproperty SaveChangesDefaultOptions

Gets or sets the SaveChangesOptions values that are used by the SaveChanges method.

Methods

Name Description
System_CAPS_pubmethod AddLink(Entity, Relationship, Entity)

Adds the specified link to the set of objects the OrganizationServiceContext is tracking.

System_CAPS_pubmethod AddObject(Entity)

Adds the specified entity to the set of entities that the OrganizationServiceContext is tracking.

System_CAPS_pubmethod AddRelatedObject(Entity, Relationship, Entity)

Adds a related entity to the OrganizationServiceContext and creates the link that defines the relationship between the two entities in a single request.

System_CAPS_pubmethod Attach(Entity)

Notifies the OrganizationServiceContext to start tracking the specified entity.

System_CAPS_pubmethod AttachLink(Entity, Relationship, Entity)

Notifies the OrganizationServiceContext to start tracking the specified link that defines a relationship between entity objects.

System_CAPS_pubmethod ClearChanges()

Clears all tracking of entities by the OrganizationServiceContext.

System_CAPS_pubmethod CreateQuery(String)

Creates a web service .NET Language-Integrated Query (LINQ) query for the specified entity.

System_CAPS_pubmethod CreateQuery<TEntity>()

Creates a Web service .NET Language-Integrated Query (LINQ) query for the specified entity.

System_CAPS_protmethod CreateQuery<TEntity>(IQueryProvider, String)

Creates a web service .NET Language-Integrated Query (LINQ) query for the specified entity.

System_CAPS_pubmethod DeleteLink(Entity, Relationship, Entity)

Changes the state of the link to deleted in the list of links being tracked by the OrganizationServiceContext.

System_CAPS_pubmethod DeleteObject(Entity)

Changes the state of the specified entity to be deleted in the OrganizationServiceContext.

System_CAPS_pubmethod DeleteObject(Entity, Boolean)

Changes the state of the specified entity to be deleted in the OrganizationServiceContext.

System_CAPS_pubmethod Detach(Entity)

Removes the entity from the set of entities that the OrganizationServiceContext is tracking.

System_CAPS_pubmethod Detach(Entity, Boolean)

Removes the entity from the set of entities that the OrganizationServiceContext is tracking.

System_CAPS_pubmethod DetachLink(Entity, Relationship, Entity)

Removes the specified link from the list of links being tracked by the OrganizationServiceContext.

System_CAPS_pubmethod Dispose()

Disposes of the service context.

System_CAPS_protmethod Dispose(Boolean)

Disposes of the service context.

System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_pubmethod Execute(OrganizationRequest)

Executes a message in the form of a request, and returns a response.

System_CAPS_protmethod Finalize()

Destructor for the OrganizationServiceContext class.(Overrides Object.Finalize().)

System_CAPS_pubmethod GetAttachedEntities()

Gets an enumerable collection of the entities attached to the OrganizationServiceContext.

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethod IsAttached(Entity)

Determines whether an entity is attached and therefore being tracked by the OrganizationServiceContext.

System_CAPS_pubmethod IsAttached(Entity, Relationship, Entity)

Determines whether an entity relationship is attached and therefore being tracked by the OrganizationServiceContext.

System_CAPS_pubmethod IsDeleted(Entity)

Determines whether an entity has been deleted.

System_CAPS_pubmethod IsDeleted(Entity, Relationship, Entity)

Determines whether a relationship has been deleted.

System_CAPS_pubmethod LoadProperty(Entity, Relationship)

Loads the related entity collection for the specified relationshp.

System_CAPS_pubmethod LoadProperty(Entity, String)

Loads deferred content for a specified property from the Web service.

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_protmethod OnBeginEntityTracking(Entity)

Virtual (Overridable) method called when entity tracking begins.

System_CAPS_protmethod OnBeginLinkTracking(Entity, Relationship, Entity)

Virtual (Overridable) method called when link tracking begins.

System_CAPS_protmethod OnEndEntityTracking(Entity)

Virtual (Overridable) method called after entity tracking ends.

System_CAPS_protmethod OnEndLinkTracking(Entity, Relationship, Entity)

Virtual (Overridable) method called after link tracking ends.

System_CAPS_protmethod OnExecute(OrganizationRequest, Exception)

Virtual (Overridable) method called after Execute is called and before an exception is re-thrown.

System_CAPS_protmethod OnExecute(OrganizationRequest, OrganizationResponse)

Virtual (Overridable) method called after Execute is called and before a response is returned.

System_CAPS_protmethod OnExecuting(OrganizationRequest)

Virtual (Overridable) method called before Execute is called.

System_CAPS_protmethod OnSaveChanges(SaveChangesResultCollection)

Virtual (Overridable) method called after an attempt to save data changes.

System_CAPS_protmethod OnSavingChanges(SaveChangesOptions)

Virtual (Overridable) method called before an attempt to save changes is performed.

System_CAPS_pubmethod SaveChanges()

Saves the changes that the OrganizationServiceContext is tracking to Microsoft Dynamics CRM.

System_CAPS_pubmethod SaveChanges(SaveChangesOptions)

Saves the changes that the OrganizationServiceContext is tracking to Microsoft Dynamics CRM.

System_CAPS_pubmethod ToString()

(Inherited from Object.)

System_CAPS_pubmethod UpdateObject(Entity)

Changes the state of the specified entity in the OrganizationServiceContext to Modified.

System_CAPS_pubmethod UpdateObject(Entity, Boolean)

Changes the state of the specified entity in the OrganizationServiceContext to Modified.

Remarks

The organization service context class maintains state on the client between interactions with the Microsoft Dynamics CRM Web service to support features such as change management. This class also manages identities and tracks changes to Microsoft Dynamics CRM data. The organization service context class implements the IQueryable interface and a .NET Language-Integrated Query (LINQ) query provider so you can write LINQ queries against Microsoft Dynamics CRM data.

Objects tracked by the organization service context are instances of entity types that represent data in Microsoft Dynamics CRM. You can designate actions to be performed on these objects and the service context tracks the changes. When the SaveChanges method is called, the service context instructs Microsoft Dynamics CRM to generate commands to create, update or delete the entities the tracked objects represent.

The code generation tool (CrmSvcUtil.exe) can be used to create a custom instance of the OrganizationServiceContext class. This class includes customizations and provides helper properties and methods for working with entities.

Several enumerations are used with the OrganizationServiceContext class. The MergeOption enumeration indicates how changes are applied to Microsoft Dynamics CRM data. The SaveChangesOptions enumeration determines how changes are managed by the service context if an error occurs.

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

Microsoft.Xrm.Sdk.Client Namespace
Create early bound entity classes with the code generation tool (CrmSvcUtil.exe)
Use the early-bound entity classes for create, update, and delete
Use the early bound entity classes to add or update associations between related records
Sample: Use the organization service context

Return to top

© 2016 Microsoft. All rights reserved. Copyright