-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update getting-started.md #296
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,20 +376,14 @@ The following JSON payload shows the expected response: | |
## 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no reason for this change. |
||
public SingleResult<Customer> Get([FromRoute] int key) | ||
{ | ||
var customer = db.Customers.SingleOrDefault(d => d.Id == key); | ||
|
||
if (customer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(customer); | ||
var item = customers.AsQueryable().Where(c => c.Id == key); | ||
return SingleResult.Create(item); | ||
} | ||
``` | ||
|
||
In the above block of code, we're using `LINQ` to write an expression to retrieve a entity with the specified key from the `Customers` table. We return a status 404 `NotFound` if we don't find any match; otherwise we return the matched entity. | ||
The SingleResult.Create method return a status 404 `NotFound` if we don't find any match; otherwise we return the matched entity. | ||
|
||
The `FromRoute` attribute is only added for documentation purposes to show that the parameter should be bound using route-data from the current request - it is neither necessary nor mandatory. | ||
|
||
|
@@ -398,14 +392,8 @@ Note that for the built-in routing conventions to route the request successfully | |
[HttpGet("odata/Customers({id})")] | ||
public ActionResult Get([FromRoute] int id) | ||
{ | ||
var customer = db.Customers.SingleOrDefault(d => d.Id == id); | ||
|
||
if (customer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(customer); | ||
var item = customers.AsQueryable().Where(c => c.Id == id); | ||
return SingleResult.Create(item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no reason for this change. |
||
} | ||
``` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason for this change.
$expand
works okay even when the return type isActionResult<Customer>
.