Class EntitySetController<TEntity, TKey>
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
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
TEntityThe entity to add to the entity set.
Returns
- TEntity
The created entity.
CreateLink(TKey, string, Uri)
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
TKeyThe key of the entity with the navigation property.
navigationProperty
stringThe name of the navigation property.
link
UriThe 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
TKeyThe entity key of the entity to delete.
DeleteLink(TKey, string, string)
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
TKeyThe key of the entity with the navigation property.
relatedKey
stringThe key of the related entity.
navigationProperty
stringThe name of the navigation property.
DeleteLink(TKey, string, Uri)
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
TKeyThe key of the entity with the navigation property.
navigationProperty
stringThe name of the navigation property.
link
UriThe 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
TKeyThe 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
TKeyThe 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
TEntityThe 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
ODataPathThe 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
TKeyThe 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
TKeyThe 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
TEntityThe 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
TKeyThe entity key of the entity to replace.
update
TEntityThe 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
TKeyThe entity key of the entity to update.
update
TEntityThe updated entity.
Returns
- TEntity
The updated entity.