@@ -22,19 +22,28 @@ This section contains the following examples:
22
22
* [ HTTP trigger, look up ID from query string] ( #http-trigger-look-up-id-from-query-string-c )
23
23
* [ HTTP trigger, get multiple docs from route data] ( #http-trigger-get-multiple-docs-from-route-data-c )
24
24
25
- The examples refer to a simple ` ToDoItem ` type:
25
+ The examples refer to a ` ToDoItem ` type and a corresponding database table :
26
26
27
27
``` cs
28
28
namespace AzureSQLSamples
29
29
{
30
30
public class ToDoItem
31
31
{
32
32
public string Id { get ; set ; }
33
+ public int Priority { get ; set ; }
33
34
public string Description { get ; set ; }
34
35
}
35
36
}
36
37
```
37
38
39
+ ``` sql
40
+ CREATE TABLE dbo .ToDo (
41
+ [Id] int primary key ,
42
+ [Priority] int null ,
43
+ [Description] nvarchar(200 ) not null
44
+ )
45
+ ```
46
+
38
47
<a id =" http-trigger-look-up-id-from-query-string-c " ></a >
39
48
40
49
### HTTP trigger, look up ID from query string
@@ -47,6 +56,7 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
47
56
48
57
``` cs
49
58
using System .Collections .Generic ;
59
+ using System .Linq ;
50
60
using Microsoft .AspNetCore .Http ;
51
61
using Microsoft .AspNetCore .Mvc ;
52
62
using Microsoft .Azure .WebJobs ;
@@ -64,17 +74,17 @@ namespace AzureSQLSamples
64
74
CommandType = System .Data .CommandType .Text ,
65
75
Parameters = " @Id={Query.id}" ,
66
76
ConnectionStringSetting = " SqlConnectionString" )]
67
- IEnumerable <ToDoItem > todoitem )
77
+ IEnumerable <ToDoItem > toDoItem )
68
78
{
69
- return new OkObjectResult (todoitem );
79
+ return new OkObjectResult (toDoItem . FirstOrDefault () );
70
80
}
71
81
}
72
82
}
73
83
```
74
84
75
- <a id =" http-trigger-get-multiple-docs -from-route-data-c " ></a >
85
+ <a id =" http-trigger-get-multiple-items -from-route-data-c " ></a >
76
86
77
- ### HTTP trigger, get multiple docs from route data
87
+ ### HTTP trigger, get multiple items from route data
78
88
79
89
The following example shows a [ C# function] ( functions-dotnet-class-library.md ) that retrieves documents returned by the query. The function is triggered by an HTTP request that uses route data to specify the value of a query parameter. That parameter is used to filter the ` ToDoItem ` records in the specified query.
80
90
@@ -91,15 +101,15 @@ namespace AzureSQLSamples
91
101
{
92
102
[FunctionName (" GetToDoItems" )]
93
103
public static IActionResult Run (
94
- [HttpTrigger (AuthorizationLevel .Anonymous , " get" , Route = " gettodoitems/{id }" )]
104
+ [HttpTrigger (AuthorizationLevel .Anonymous , " get" , Route = " gettodoitems/{priority }" )]
95
105
HttpRequest req ,
96
- [Sql (" select * from dbo.ToDo where Id > @Id " ,
106
+ [Sql (" select * from dbo.ToDo where [Priority] > @Priority " ,
97
107
CommandType = System .Data .CommandType .Text ,
98
- Parameters = " @Id={id }" ,
108
+ Parameters = " @Priority={priority }" ,
99
109
ConnectionStringSetting = " SqlConnectionString" )]
100
- IEnumerable <ToDoItem > todoitem )
110
+ IEnumerable <ToDoItem > toDoItems )
101
111
{
102
- return new OkObjectResult (todoitem );
112
+ return new OkObjectResult (toDoItems );
103
113
}
104
114
}
105
115
}
@@ -126,15 +136,15 @@ The attribute's constructor takes the SQL command text, the command type, parame
126
136
Here's a ` Sql ` attribute example in a method signature:
127
137
128
138
``` csharp
129
- [FunctionName (" ReturnRecords " )]
139
+ [FunctionName (" GetToDoItems " )]
130
140
public static IActionResult Run (
131
- [HttpTrigger (AuthorizationLevel .Anonymous , " get" , Route = " gettodoitems/{id }" )]
141
+ [HttpTrigger (AuthorizationLevel .Anonymous , " get" , Route = " gettodoitems/{priority }" )]
132
142
HttpRequest req ,
133
- [Sql (" select * from dbo.ToDo where Id > @Id " ,
143
+ [Sql (" select * from dbo.ToDo where [Priority] > @Priority " ,
134
144
CommandType = System .Data .CommandType .Text ,
135
- Parameters = " @Id={id }" ,
145
+ Parameters = " @Priority={priority }" ,
136
146
ConnectionStringSetting = " SqlConnectionString" )]
137
- IEnumerable < ToDoItem > todoitem )
147
+ IEnumerable < ToDoItem > toDoItems )
138
148
{
139
149
.. .
140
150
}
0 commit comments