Conversation
Adapt get method by key
|
Learn Build status updates of commit d8c75bd: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
|
Learn Build status updates of commit 4933754: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
|
Learn Build status updates of commit 3602f07: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
|
@microsoft-github-policy-service agree |
|
Learn Build status updates of commit e9d9d88: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
| } | ||
|
|
||
| [EnableQuery] | ||
| public ActionResult<Customer> Get([FromRoute] int key) |
There was a problem hiding this comment.
There's no reason for this change. $expand works okay even when the return type is ActionResult<Customer>.
| ## Request a single entity | ||
| To support this request, we add a controller action named `Get` (or `GetCustomer`) to the `CustomersController` class. The action should accept a single parameter named `key` of type `int` - same type as the entity's key property: | ||
| ```csharp | ||
| public ActionResult<Customer> Get([FromRoute] int key) |
There was a problem hiding this comment.
There's no reason for this change. $expand works okay even when the return type is ActionResult<Customer>.
|
|
||
| return Ok(customer); | ||
| var item = customers.AsQueryable().Where(c => c.Id == id); | ||
| return SingleResult.Create(item); |
There was a problem hiding this comment.
There's no reason for this change. $expand works okay even when the return type is ActionResult.
|
@michelcedric There's no reason for the changes that you proposed. Query options work okay even when the return type is |
|
@gathogojr |
@michelcedric The sample code in this tutorial uses an in-memory collection as a data store. In my opinion, it'd be more ideal to have a different article with code samples that are relevant to an SQL Server data store where we can employ the use of |


Adapt get method by key
An odata endpoint must return a IQueryable.
If you evaluate it directly in the return of the controller method, the odata query feature (example : expand) can't working.
If you directly return the queryable you return an array with only one element.
You can fix that with the usage of
SingleResult.Create method form odata