@@ -118,6 +118,78 @@ The included Dockerfile-websample builds, packages and runs the web sample proje
118
118
119
119
docker run -p 80:80 garvincasimir/datatables-aspnet-core-sample:0.0.2
120
120
121
+ Projections
122
+ ========================
123
+ I recommended always using a projection with the query that is sent to the parser. This strategy has 4 main benefits:
124
+ * Avoid inadverently serializing and sending sensitive fields to the client.
125
+ * Avoid custom non-database fields in your model
126
+ * Inlcude parent table fields
127
+ * Include computed fields
128
+
129
+ Below is an example of a self referencing table:
130
+
131
+ | EmployeeID | FirstName | LastName | ManagerID | Token | BirthDate |
132
+ | ----------- | --------- | -------- | -------- | ----------- | --------- |
133
+ | 1 | Mary | Joe | null | s38fjsf8dj | 3/3/1921 |
134
+ | 2 | Jane | Jim | 1 | 9fukfdflsl | 2/2/1921 |
135
+ | 3 | Rose | Jack | 1 | s9fkf;;d; | 1/1/1931 |
136
+
137
+
138
+ The model class:
139
+
140
+ ``` csharp
141
+ public class Employee
142
+ {
143
+ public int EmployeeID {get ;set ;}
144
+ public string FirstName {get ;set ;}
145
+ public string LastName {get ;set ;}
146
+ public int ? ManagerID {get ;set ;}
147
+ [ForeignKey (" ManagerID" )]
148
+ public Employee Manager {get ;set ;}
149
+ public string Token {get ;set ;}
150
+ public DateTime BirthDate {get ;set ;}
151
+ }
152
+ ```
153
+
154
+ Projection class:
155
+
156
+ ``` csharp
157
+ public class EmployeeResult
158
+ {
159
+ public int EmployeeID {get ;set ;}
160
+ public string FullName {get ;set ;}
161
+ public int ? ManagerID {get ;set ;}
162
+ public string ManagerFullName {get ;set ;}
163
+ public DateTime BirthDate {get ;set ;}
164
+ public string BirthDateFormatted
165
+ {
166
+ get
167
+ {
168
+ return String .Format (" {0:M/d/yyyy}" , BirthDate );
169
+ }
170
+ }
171
+ }
172
+ ```
173
+ Query:
174
+
175
+ ``` csharp
176
+ var query = from e in context .Employees
177
+ let FullName = e .FirstName + " " + e .LastName
178
+ let ManagerFullName = e .Manager .FirstName + " " + e .Manager .LastName
179
+ select new EmployeeResult
180
+ {
181
+ EmployeeID = e .EmployeeID ,
182
+ FullName = FullName ,
183
+ ManagerID = e .ManagerID ,
184
+ ManagerFullName = ManagerFullName ,
185
+ BirthDate = e .BirthDate
186
+ };
187
+
188
+ var parser = new Parser <EmployeeResult >(Request .Form , query );
189
+
190
+ ```
191
+
192
+
121
193
Custom Filter Expressions
122
194
========================
123
195
The parser builds a set of expressions based on the settings and filter text sent from Datatables. The end result is a * WHERE* clause which looks something like this:
0 commit comments