Table of Contents

Class EntitySetController<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 synchronous version of AsyncEntitySetController<TEntity, TKey>.

[CLSCompliant(false)]
[ODataNullValue]
public abstract class EntitySetController<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
EntitySetController<TEntity, TKey>
Inherited Members

Constructors

EntitySetController()

protected EntitySetController()

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

CreateEntity(TEntity)

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

protected virtual TEntity CreateEntity(TEntity entity)

Parameters

entity TEntity

The entity to add to the entity set.

Returns

TEntity

The created entity.

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

public virtual void 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.

Delete(TKey)

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

public virtual void Delete(TKey key)

Parameters

key TKey

The entity key of the entity to delete.

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

public virtual void 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.

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

public virtual void 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.

Get()

This method should be overridden to handle GET requests that attempt to retrieve entities from the entity set.

public virtual IQueryable<TEntity> Get()

Returns

IQueryable<TEntity>

The matching entities from the entity set.

Get(TKey)

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

public virtual HttpResponseMessage Get(TKey key)

Parameters

key TKey

The entity key of the entity to retrieve.

Returns

HttpResponseMessage

The response message to send back to the client.

GetEntityByKey(TKey)

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

protected virtual TEntity GetEntityByKey(TKey key)

Parameters

key TKey

The entity key of the entity to retrieve.

Returns

TEntity

The retrieved entity, 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 HttpResponseMessage HandleUnmappedRequest(ODataPath odataPath)

Parameters

odataPath ODataPath

The OData path of the request.

Returns

HttpResponseMessage

The response message to send back to the client.

Patch(TKey, Delta<TEntity>)

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

public virtual 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

HttpResponseMessage

The response message to send back to the client.

PatchEntity(TKey, Delta<TEntity>)

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

protected virtual TEntity PatchEntity(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

TEntity

The updated entity.

Post(TEntity)

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

public virtual HttpResponseMessage Post(TEntity entity)

Parameters

entity TEntity

The entity to insert into the entity set.

Returns

HttpResponseMessage

The response message to send back to the client.

Put(TKey, TEntity)

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

public virtual HttpResponseMessage Put(TKey key, TEntity update)

Parameters

key TKey

The entity key of the entity to replace.

update TEntity

The updated entity.

Returns

HttpResponseMessage

The response message to send back to the client.

UpdateEntity(TKey, TEntity)

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

protected virtual TEntity UpdateEntity(TKey key, TEntity update)

Parameters

key TKey

The entity key of the entity to update.

update TEntity

The updated entity.

Returns

TEntity

The updated entity.