OrganizationServiceContext OrganizationServiceContext OrganizationServiceContext OrganizationServiceContext Class

Definition

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

public ref class OrganizationServiceContext : IDisposable
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA9881:ClassesShouldBeSealed", Justification="This class is used as base by crmsvcutil")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
public class OrganizationServiceContext : IDisposable
type OrganizationServiceContext = class
    interface IDisposable
Public Class OrganizationServiceContext
Implements IDisposable
Inheritance
OrganizationServiceContextOrganizationServiceContextOrganizationServiceContextOrganizationServiceContext
Attributes
Implements

Remarks

The organization service context class maintains state on the client between interactions with the Microsoft Dynamics 365 Web service to support features such as change management. This class also manages identities and tracks changes to Microsoft Dynamics 365 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 365 data.

Objects tracked by the organization service context are instances of entity types that represent data in Microsoft Dynamics 365. 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 365 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 365 data. The SaveChangesOptions enumeration determines how changes are managed by the service context if an error occurs.

Constructors

OrganizationServiceContext(IOrganizationService) OrganizationServiceContext(IOrganizationService) OrganizationServiceContext(IOrganizationService) OrganizationServiceContext(IOrganizationService)

Creates a new instance of the OrganizationServiceContext class.

Properties

ConcurrencyBehavior ConcurrencyBehavior ConcurrencyBehavior ConcurrencyBehavior

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

MergeOption MergeOption MergeOption MergeOption

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

QueryProvider QueryProvider QueryProvider QueryProvider

Gets the query provider.

SaveChangesDefaultOptions SaveChangesDefaultOptions SaveChangesDefaultOptions SaveChangesDefaultOptions

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

Methods

AddLink(Entity, Relationship, Entity) AddLink(Entity, Relationship, Entity) AddLink(Entity, Relationship, Entity) AddLink(Entity, Relationship, Entity)

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

AddObject(Entity) AddObject(Entity) AddObject(Entity) AddObject(Entity)

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

AddRelatedObject(Entity, Relationship, Entity) AddRelatedObject(Entity, Relationship, Entity) AddRelatedObject(Entity, Relationship, Entity) 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.

Attach(Entity) Attach(Entity) Attach(Entity) Attach(Entity)

Notifies the OrganizationServiceContext to start tracking the specified entity.

AttachLink(Entity, Relationship, Entity) AttachLink(Entity, Relationship, Entity) AttachLink(Entity, Relationship, Entity) AttachLink(Entity, Relationship, Entity)

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

ClearChanges() ClearChanges() ClearChanges() ClearChanges()

Clears all tracking of entities by the OrganizationServiceContext.

CreateQuery(String) CreateQuery(String) CreateQuery(String) CreateQuery(String)

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

CreateQuery<TEntity>(IQueryProvider, String) CreateQuery<TEntity>(IQueryProvider, String) CreateQuery<TEntity>(IQueryProvider, String) CreateQuery<TEntity>(IQueryProvider, String)

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

CreateQuery<TEntity>() CreateQuery<TEntity>() CreateQuery<TEntity>() CreateQuery<TEntity>()

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

DeleteLink(Entity, Relationship, Entity) DeleteLink(Entity, Relationship, Entity) DeleteLink(Entity, Relationship, Entity) DeleteLink(Entity, Relationship, Entity)

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

DeleteObject(Entity) DeleteObject(Entity) DeleteObject(Entity) DeleteObject(Entity)

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

DeleteObject(Entity, Boolean) DeleteObject(Entity, Boolean) DeleteObject(Entity, Boolean) DeleteObject(Entity, Boolean)

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

Detach(Entity) Detach(Entity) Detach(Entity) Detach(Entity)

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

Detach(Entity, Boolean) Detach(Entity, Boolean) Detach(Entity, Boolean) Detach(Entity, Boolean)

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

DetachLink(Entity, Relationship, Entity) DetachLink(Entity, Relationship, Entity) DetachLink(Entity, Relationship, Entity) DetachLink(Entity, Relationship, Entity)

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

Dispose() Dispose() Dispose() Dispose()

Disposes of the service context.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Disposes of the service context.

Execute(OrganizationRequest) Execute(OrganizationRequest) Execute(OrganizationRequest) Execute(OrganizationRequest)

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

Finalize() Finalize() Finalize() Finalize()

Destructor for the OrganizationServiceContext class.

GetAttachedEntities() GetAttachedEntities() GetAttachedEntities() GetAttachedEntities()

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

IsAttached(Entity) IsAttached(Entity) IsAttached(Entity) IsAttached(Entity)

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

IsAttached(Entity, Relationship, Entity) IsAttached(Entity, Relationship, Entity) IsAttached(Entity, Relationship, Entity) IsAttached(Entity, Relationship, Entity)

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

IsDeleted(Entity) IsDeleted(Entity) IsDeleted(Entity) IsDeleted(Entity)

Determines whether an entity has been deleted.

IsDeleted(Entity, Relationship, Entity) IsDeleted(Entity, Relationship, Entity) IsDeleted(Entity, Relationship, Entity) IsDeleted(Entity, Relationship, Entity)

Determines whether a relationship has been deleted.

LoadProperty(Entity, Relationship) LoadProperty(Entity, Relationship) LoadProperty(Entity, Relationship) LoadProperty(Entity, Relationship)

Loads the related entity collection for the specified relationshp.

LoadProperty(Entity, String) LoadProperty(Entity, String) LoadProperty(Entity, String) LoadProperty(Entity, String)

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

OnBeginEntityTracking(Entity) OnBeginEntityTracking(Entity) OnBeginEntityTracking(Entity) OnBeginEntityTracking(Entity)

Virtual (Overridable) method called when entity tracking begins.

OnBeginLinkTracking(Entity, Relationship, Entity) OnBeginLinkTracking(Entity, Relationship, Entity) OnBeginLinkTracking(Entity, Relationship, Entity) OnBeginLinkTracking(Entity, Relationship, Entity)

Virtual (Overridable) method called when link tracking begins.

OnEndEntityTracking(Entity) OnEndEntityTracking(Entity) OnEndEntityTracking(Entity) OnEndEntityTracking(Entity)

Virtual (Overridable) method called after entity tracking ends.

OnEndLinkTracking(Entity, Relationship, Entity) OnEndLinkTracking(Entity, Relationship, Entity) OnEndLinkTracking(Entity, Relationship, Entity) OnEndLinkTracking(Entity, Relationship, Entity)

Virtual (Overridable) method called after link tracking ends.

OnExecute(OrganizationRequest, OrganizationResponse) OnExecute(OrganizationRequest, OrganizationResponse) OnExecute(OrganizationRequest, OrganizationResponse) OnExecute(OrganizationRequest, OrganizationResponse)

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

OnExecute(OrganizationRequest, Exception) OnExecute(OrganizationRequest, Exception) OnExecute(OrganizationRequest, Exception) OnExecute(OrganizationRequest, Exception)

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

OnExecuting(OrganizationRequest) OnExecuting(OrganizationRequest) OnExecuting(OrganizationRequest) OnExecuting(OrganizationRequest)

Virtual (Overridable) method called before Execute(OrganizationRequest) is called.

OnSaveChanges(SaveChangesResultCollection) OnSaveChanges(SaveChangesResultCollection) OnSaveChanges(SaveChangesResultCollection) OnSaveChanges(SaveChangesResultCollection)

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

OnSavingChanges(SaveChangesOptions) OnSavingChanges(SaveChangesOptions) OnSavingChanges(SaveChangesOptions) OnSavingChanges(SaveChangesOptions)

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

SaveChanges() SaveChanges() SaveChanges() SaveChanges()

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

SaveChanges(SaveChangesOptions) SaveChanges(SaveChangesOptions) SaveChanges(SaveChangesOptions) SaveChanges(SaveChangesOptions)

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

UpdateObject(Entity) UpdateObject(Entity) UpdateObject(Entity) UpdateObject(Entity)

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

UpdateObject(Entity, Boolean) UpdateObject(Entity, Boolean) UpdateObject(Entity, Boolean) UpdateObject(Entity, Boolean)

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

Applies to