Skip to content

Commit 9431b99

Browse files
update about cte
1 parent 9e158b9 commit 9431b99

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

cte.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# Common Table Expression
2-
A common table expression (CTE) can be thought of as a temporary result set, it has some advantages over the sub query approach.
2+
A common table expression (CTE) can be thought of as a temporary result set
33

4-
In Sql, usually CTE is represented as a `with` clause.
4+
## Some notes about the CTE approach
5+
6+
- CTE are easier to read
7+
Nested queries are hard to inspect, you have to undertand all the nested queries first, then go up to the main query, while in the CTE approach, the read process is more natural, from top to bottom.
8+
9+
- Ability to overload existing tables
10+
You can overload existing tables this may help for testing purposes.
11+
12+
In Sql, CTE is represented as a `with` clause.
513

614
## With
715
To add a CTE to your query simply use the `With` method.
@@ -27,7 +35,7 @@ SELECT [Posts].*, [ActivePosts].[Count] FROM [Posts] INNER JOIN [ActivePosts] ON
2735
```
2836

2937
## WithRaw
30-
You can use the `WithRaw` method if you want to pass an Sql Expression.
38+
You can use the `WithRaw` method if you want to pass a raw Sql Expression.
3139

3240
```cs
3341
var query = new Query("Posts")

index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ It uses parameter binding technique to protect your application against SQL inje
1818

1919
In addition to protection against SQL injection attacks, this technique speeds up your query execution by letting the SQL engine caches and reuses the same query plan even if the parameters are changed.
2020

21+
<img src="./images/pic.jpg">
22+
2123
```cs
2224
IEnumerable<Post> posts = await db.Query("Posts")
2325
.Where("Likes", ">", 10)

0 commit comments

Comments
 (0)