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
Copy file name to clipboardExpand all lines: README.md
+71Lines changed: 71 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -314,6 +314,77 @@ var appliedQueryable = queryableRecipe.ApplyQueryKitFilter(input, config);
314
314
varrecipes=awaitappliedQueryable.ToListAsync();
315
315
```
316
316
317
+
#### Filtering Raw SQL Projections
318
+
319
+
QueryKit can also be used with raw SQL queries via EF Core's `SqlQueryRaw`. This is particularly useful when you need to work with complex SQL queries that include joins, aggregations, or database-specific functions.
320
+
321
+
> 💡 You can use projections without using raw sql
322
+
323
+
Here's an example using a school domain:
324
+
325
+
```csharp
326
+
publicclassStudentEnrollmentDto
327
+
{
328
+
publicGuidId { get; set; }
329
+
publicstringStudentFirstName { get; set; }
330
+
publicstringStudentLastName { get; set; }
331
+
publicstringStudentFullName { get; set; }
332
+
publicintStudentAge { get; set; }
333
+
publicGuidCourseId { get; set; }
334
+
publicstringCourseName { get; set; }
335
+
publicDateTimeEnrolledOn { get; set; }
336
+
publicDateTime? CourseStartDate { get; set; }
337
+
}
338
+
339
+
varsql=
340
+
$"""
341
+
SELECT
342
+
e.id as "Id",
343
+
COALESCE(s.first_name, '') as "StudentFirstName",
344
+
COALESCE(s.last_name, '') as "StudentLastName",
345
+
COALESCE(s.first_name, '') || ' ' || COALESCE(s.last_name, '') as "StudentFullName",
- Raw SQL projections work seamlessly with QueryKit's filtering and sorting
384
+
- You can include computed fields (like `StudentFullName`) and nested fields from joins (like `CourseStartDate`)
385
+
- Property mappings allow you to use friendly query names that differ from the DTO property names
386
+
- The resulting queryable can be further filtered and sorted by QueryKit before materializing to a list
387
+
317
388
#### Filtering Collections
318
389
319
390
You can also filter into collections with QueryKit by using most of the normal operators. For example, if I wanted to filter for recipes that only have an ingredient named `salt`, I could do something like this:
0 commit comments