question

95325334 avatar image
0 Votes"
95325334 asked ·

Select only few columns from a table to map with Odata Select query on C# Web API

We have a table in the database which has multiple columns. We only want a query which will return only requested columns. These requested columns will from Odata Select Query requested using C# Web API.
For Example, I have an EmployeeTable which has below structure in SQL

51233-image.png

And I am calling below sample API to get the results
http://domain/controller/method?Select=EmployeeID,EmployeeName

This query should get only above 2 columns from the database; in the current scenario - Database returns all the columns and Odata configurations in Web API filters out the response before returning it to the user
Please help with how to implement this in the database.

dotnet-aspnet-webapi
image.png (4.7 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VaibhavChaudhari avatar image
0 Votes"
VaibhavChaudhari answered ·

I am not aware of .Net but the OData query for select should be something like below. Dollar sign is required

http://localhost/odata/Products?$select=Price,Name


Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered ·
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.