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
{{ message }}
Repository navigation
Commit 80be0b8
Browse filesBrowse the repository at this point in the historyBrowse files
> **Tip:** Replace `*` with the [latest stable version](https://www.nuget.org/packages/EntityFrameworkCore.Projectables/).
45
+
46
+
## Step 2 — Define Your Entities
47
+
48
+
Add `[Projectable]` to any property or method whose body you want EF Core to translate to SQL:
6
49
7
50
```csharp
51
+
usingEntityFrameworkCore.Projectables;
52
+
8
53
publicclassUser
9
54
{
10
55
publicintId { get; set; }
@@ -43,7 +88,21 @@ public class Product
43
88
}
44
89
```
45
90
46
-
## Step 2 — Enable Projectables on Your DbContext
91
+
The source generator runs at **compile time** and emits a companion `Expression<TDelegate>` for each `[Projectable]` member — no runtime reflection.
92
+
93
+
## Step 3 — Enable Projectables on Your DbContext
94
+
95
+
Call `UseProjectables()` when configuring your `DbContextOptions`. The extension method is in the `Microsoft.EntityFrameworkCore` namespace and is included in the `EntityFrameworkCore.Projectables` package.
96
+
97
+
### With DI (`AddDbContext`)
98
+
99
+
```csharp
100
+
services.AddDbContext<AppDbContext>(options=>
101
+
options.UseSqlServer(connectionString)
102
+
.UseProjectables());
103
+
```
104
+
105
+
### With `OnConfiguring`
47
106
48
107
```csharp
49
108
publicclassAppDbContext : DbContext
@@ -55,12 +114,12 @@ public class AppDbContext : DbContext
55
114
{
56
115
optionsBuilder
57
116
.UseSqlServer("your-connection-string")
58
-
.UseProjectables();// Enable the runtime interceptor
117
+
.UseProjectables();
59
118
}
60
119
}
61
120
```
62
121
63
-
## Step 3 — Use Projectable Members in Queries
122
+
## Step 4 — Use Projectable Members in Queries
64
123
65
124
Now you can use `GrandTotal`, `Subtotal`, and `Tax`**directly in any LINQ query**:
66
125
@@ -86,7 +145,7 @@ var sortedOrders = dbContext.Orders
86
145
.ToList();
87
146
```
88
147
89
-
## Step 4 — Check the Generated SQL
148
+
## Step 5 — Check the Generated SQL
90
149
91
150
Use `ToQueryString()` to inspect the SQL EF Core generates:
92
151
@@ -98,7 +157,7 @@ var query = dbContext.Orders
98
157
Console.WriteLine(query.ToQueryString());
99
158
```
100
159
101
-
The `GrandTotal` property — which itself uses `Subtotal` (which is also `[Projectable]`) — is fully inlined:
160
+
The `GrandTotal` property composes `Subtotal` (which is also `[Projectable]`) — both are fully inlined into SQL:
Copy file name to clipboardExpand all lines: docs/index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ hero:
7
7
tagline: Write properties and methods once — use them anywhere in your LINQ queries, translated to efficient SQL automatically.
8
8
actions:
9
9
- theme: brand
10
-
text: Get Started
10
+
text: Introduction
11
11
link: /guide/introduction
12
12
- theme: alt
13
13
text: Quick Start
@@ -27,7 +27,7 @@ features:
27
27
28
28
- icon: ⚡
29
29
title: Performance-First Design
30
-
details: Limited compatibility mode expands and caches queries after their first execution. Subsequent calls skip the expansion step entirely, often outperforming native EF Core.
30
+
details: Limited compatibility mode expands and caches queries after their first execution. Subsequent calls skip the expansion step entirely.
0 commit comments