You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assumption in this example is that your connection string is stored in appsettings.config file under key MyConnection.
@@ -90,7 +90,7 @@ To implement OData Service, you would need to add the TableSpec object that desc
90
90
```
91
91
IQueryPipe sqlQuery = null;
92
92
93
-
TableSpec tableSpec = new TableSpec("dbo.People", "name,surname,address,town");
93
+
TableSpec tableSpec = new TableSpec(schema: "dbo", table: "People", columns: "name,surname,address,town");
94
94
95
95
public PeopleController(IQueryPipe sqlQueryService)
96
96
{
@@ -107,13 +107,15 @@ First, you need to parse Request parameters using UriParser in order to extract
107
107
public async Task OData()
108
108
{
109
109
await this
110
-
.ODataHandler(tableSpec, pipe)
111
-
.Process();
110
+
.OData(tableSpec)
111
+
.Process(pipe);
112
112
}
113
113
```
114
114
115
115
That's everything that you need to do. With three lines of code you can create OData service on any table. You can find more more details in [OData documentation](doc/odata.md) page.
116
116
117
+
You can see how to create OData services in the [SQL Server Wide World Importers sample app](https://github.com/Microsoft/sql-server-samples/blob/master/samples/databases/wide-world-importers/wwi-app/Controllers/ODataController.cs).
118
+
117
119
## Implement REST service that process JQuery DataTables Ajax request
118
120
119
121
[JQuery DataTables](https://datatables.net/) is JQuery component that enhances HTML tables and adds rich client-side functionalities such as filtering, pagination, ordering by columns, etc. JQuery DataTables component might work in two modes:
@@ -144,7 +146,7 @@ In order to implement REST service that handles AJAX requests that JQuery DataTa
144
146
```
145
147
IQueryPipe sqlQuery = null;
146
148
147
-
TableSpec tableSpec = new TableSpec("dbo.People", "name,surname,address,town");
149
+
TableSpec tableSpec = new TableSpec(schema: "dbo", table: "People", columns: "name,surname,address,town");
148
150
149
151
public PeopleController(IQueryPipe sqlQueryService)
150
152
{
@@ -156,30 +158,17 @@ Now you need to create async method that will serve JQuery DataTables AJAX reque
156
158
- UriParser that will parse Http request parameters that JQuery DataTables component sends
157
159
- QueryBuilder that will create T-SQL query that will be executed.
158
160
159
-
First, you need to parse Request parameters using UriParser in order to extract the definition of query (QuerySpec object). Then you need to use QueryBuilder to create SQL query using the QuerySpec. Then you need to provide sql query to QueryPipe that will stream results to JQuery DataTables using Response.Body:
161
+
First, you need to parse Request parameters using UriParser in order to extract the definition of query (`QuerySpec` object). Then you need to use QueryBuilder to create SQL query using the QuerySpec. Then you need to provide sql query to QueryPipe that will stream results to JQuery DataTables using `Response.Body`:
160
162
161
163
```
162
-
// GET api/People
163
-
[HttpGet]
164
-
public async Task Get(int draw, int start, int length)
165
-
{
166
-
var querySpec = JQueryDataTables.UriParser.Parse(tableSpec, this.Request);
167
-
var sql = QueryBuilder.Build(querySpec, tableSpec).AsJson();
[JQuery DataTables](https://datatables.net/) component requires AJAX response in some pre-defined format, so you would need to wrap results from database with header that contains number of total and number of filtered records.
183
171
Note that JQuery DataTables plugin uses **recordsTotal** and **recordsFiltered** to build pagination. Since you would need two additional queries . Reccomendation is to use alternative (paging plugins)[https://datatables.net/plug-ins/pagination/]
184
172
that don't require these options.
185
173
174
+
You can see how to create services that are used by JQuery DataTables in the [SQL Server Wide World Importers sample app](https://github.com/Microsoft/sql-server-samples/blob/master/samples/databases/wide-world-importers/wwi-app/Controllers/TableController.cs).
0 commit comments