Delete record with composite primary key in OData

1.6k Views Asked by At

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?

1

There are 1 best solutions below

0
nandita morajkar On BEST ANSWER

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)