Table of Contents

Class AsyncEntitySetController<TEntity, TKey>

Namespace
System.Web.Http.OData
Assembly
System.Web.Http.OData.dll

Provides a convenient starting point for a controller that exposes an OData entity set. This is the asynchronous version of EntitySetController<TEntity, TKey>.

[CLSCompliant(false)]
[ODataNullValue]
public abstract class AsyncEntitySetController<TEntity, TKey> : ODataController where TEntity : class

Type Parameters

TEntity

The type associated with the exposed entity set's entity type.

TKey

The type associated with the entity key of the exposed entity set's entity type.

Inheritance
AsyncEntitySetController<TEntity, TKey>
Inherited Members

Constructors

AsyncEntitySetController()

protected AsyncEntitySetController()

Properties

ODataPath

Gets the OData path of the current request.

public ODataPath ODataPath { get; }

Property Value

ODataPath

QueryOptions

Gets the OData query options of the current request.

public ODataQueryOptions<TEntity> QueryOptions { get; }

Property Value

ODataQueryOptions<TEntity>

Methods

CreateEntityAsync(TEntity)

This method should be overridden to create a new entity in the entity set.

protected virtual Task<TEntity> CreateEntityAsync(TEntity entity)

Parameters

entity TEntity

The entity to add to the entity set.

Returns

Task<TEntity>

A Task that contains the created entity when it completes.

This method should be overridden to handle POST and PUT requests that attempt to create a link between two entities.

public virtual Task CreateLink(TKey key, string navigationProperty, Uri link)

Parameters

key TKey

The key of the entity with the navigation property.

navigationProperty string

The name of the navigation property.

link Uri

The URI of the entity to link.

Returns

Task

A Task that completes when the link has been successfully created.

Delete(TKey)

This method should be overridden to handles DELETE requests for deleting existing entities from the entity set.

public virtual Task Delete(TKey key)

Parameters

key TKey

The entity key of the entity to delete.

Returns

Task

A Task that completes when the entity has been successfully deleted.

This method should be overridden to handle DELETE requests that attempt to break a relationship between two entities.

public virtual Task DeleteLink(TKey key, string relatedKey, string navigationProperty)

Parameters

key TKey

The key of the entity with the navigation property.

relatedKey string

The key of the related entity.

navigationProperty string

The name of the navigation property.

Returns

Task

A Task that completes when the link has been successfully deleted.

This method should be overridden to handle DELETE requests that attempt to break a relationship between two entities.

public virtual Task DeleteLink(TKey key, string navigationProperty, Uri link)

Parameters

key TKey

The key of the entity with the navigation property.

navigationProperty string

The name of the navigation property.

link Uri

The URI of the entity to remove from the navigation property.

Returns

Task

A Task that completes when the link has been successfully deleted.

Get()

This method should be overridden to handle GET requests that attempt to retrieve entities from the entity set. This method should asynchronously compute the matching entities by applying the request's query options.

public virtual Task<IEnumerable<TEntity>> Get()

Returns

Task<IEnumerable<TEntity>>

A Task that contains the matching entities from the entity set when it completes.

Get(TKey)

Handles GET requests that attempt to retrieve an individual entity by key from the entity set.

public virtual Task<HttpResponseMessage> Get(TKey key)

Parameters

key TKey

The entity key of the entity to retrieve.

Returns

Task<HttpResponseMessage>

A Task that contains the response message to send back to the client when it completes.

GetEntityByKeyAsync(TKey)

This method should be overridden to retrieve an entity by key from the entity set.

protected virtual Task<TEntity> GetEntityByKeyAsync(TKey key)

Parameters

key TKey

The entity key of the entity to retrieve.

Returns

Task<TEntity>

A Task that contains the retrieved entity when it completes, or null if an entity with the specified entity key cannot be found in the entity set.

GetKey(TEntity)

This method should be overridden to get the entity key of the specified entity.

protected virtual TKey GetKey(TEntity entity)

Parameters

entity TEntity

The entity.

Returns

TKey

The entity key value

HandleUnmappedRequest(ODataPath)

This method should be overridden to handle all unmapped OData requests.

public virtual Task<HttpResponseMessage> HandleUnmappedRequest(ODataPath odataPath)

Parameters

odataPath ODataPath

The OData path of the request.

Returns

Task<HttpResponseMessage>

A Task that contains the response message to send back to the client when it completes.

Patch(TKey, Delta<TEntity>)

Handles PATCH and MERGE requests to partially update a single entity in the entity set.

public virtual Task<HttpResponseMessage> Patch(TKey key, Delta<TEntity> patch)

Parameters

key TKey

The entity key of the entity to update.

patch Delta<TEntity>

The patch representing the partial update.

Returns

Task<HttpResponseMessage>

A Task that contains the response message to send back to the client when it completes.

PatchEntityAsync(TKey, Delta<TEntity>)

This method should be overridden to apply a partial update to an existing entity in the entity set.

protected virtual Task<TEntity> PatchEntityAsync(TKey key, Delta<TEntity> patch)

Parameters

key TKey

The entity key of the entity to update.

patch Delta<TEntity>

The patch representing the partial update.

Returns

Task<TEntity>

A Task that contains the updated entity when it completes.

Post(TEntity)

Handles POST requests that create new entities in the entity set.

public virtual Task<HttpResponseMessage> Post(TEntity entity)

Parameters

entity TEntity

The entity to insert into the entity set.

Returns

Task<HttpResponseMessage>

A Task that contains the response message to send back to the client when it completes.

Put(TKey, TEntity)

Handles PUT requests that attempt to replace a single entity in the entity set.

public virtual Task<HttpResponseMessage> Put(TKey key, TEntity update)

Parameters

key TKey

The entity key of the entity to replace.

update TEntity

The updated entity.

Returns

Task<HttpResponseMessage>

A Task that contains the response message to send back to the client when it completes.

UpdateEntityAsync(TKey, TEntity)

This method should be overridden to update an existing entity in the entity set.

protected virtual Task<TEntity> UpdateEntityAsync(TKey key, TEntity update)

Parameters

key TKey

The entity key of the entity to update.

update TEntity

The updated entity.

Returns

Task<TEntity>

A Task that contains the updated entity when it completes.