restasp.net-web-api2odataasp.net-web-api-odata

Delete record with composite primary key in OData


I have an entity Student. Below is the signature of delete method in ASP.net WebAPI for OData.

public async Task<IHttpActionResult> Delete([FromODataUri] int key)

The Student has composite primary key. When called from Postman, with

http://localhost:52484/Students/1

it doesn't hit the Delete method. But it works with other entity with single primary key.

Any suggestions?


Solution

  • Kindly prefix param with 'key' for composite key Entity. OData v4

    Refer the example below:

        public async Task<IHttpActionResult> Delete([FromODataUri] int keySudentId, [FromODataUri] int keyClassId)
        {
          //Delete code here
        }
    

    OData Url http://localhost:52484/Student(SudentId=1,ClassId=2)