Suppose I have collection of SupplierEntity need to expose as OData:
1. Inherit from EntitySetController<SupplierEntity, int>
2. For getting collections of SupplierEntity objects, override IQueryable<SupplierEntity> Get() method in base class
3. For getting single SupplierEntity object, override GetEntityByKey(int key) method
5. For updating SupplierEntity object, override UpdateEntity(int iSupplierID, SupplierEntity entity) method
5. For deleting SupplierEntity object, override Delete(int key) method
1. Inherit from EntitySetController<SupplierEntity, int>
2. For getting collections of SupplierEntity objects, override IQueryable<SupplierEntity> Get() method in base class
public override IQueryable<SupplierEntity> Get()
3. For getting single SupplierEntity object, override GetEntityByKey(int key) method
protected override SupplierEntity GetEntityByKey(int key)
4. For creating SupplierEntity object, override both CreateEntity(SupplierEntity entity) and GetKey(SupplierEntity entity) methodsprotected override SupplierEntityCreateEntity(SupplierEntity entity)
protected override int GetKey(SupplierEntity entity)
Note: In CreateEntity method, when the entity has been created in database and the key have been assigned by database, we need to assign this key to entity parameter and return it back to client.5. For updating SupplierEntity object, override UpdateEntity(int iSupplierID, SupplierEntity entity) method
protected override SupplierEntity UpdateEntity(int key, SupplierEntity update)
5. For deleting SupplierEntity object, override Delete(int key) method
public override void Delete(int key)
Note: The parameter name has to be key. Otherwise you would get the 404 error.
Comments