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
@@ -92,7 +94,7 @@ Currently, there is no support for overloaded methods. Each method name needs to
92
94
No, the runtime component injects itself into the EFCore query compilation pipeline, thus having no impact on the database provider used. Of course, you're still limited to whatever your database provider can do.
93
95
94
96
#### Are there performance implications that I should be aware of?
95
-
There are two compatibility modes: Limited and Full (Default). Most of the time, limited compatibility mode is sufficient. However, if you are running into issues with failed query compilation, then you may want to stick with Full compatibility mode. With Full compatibility mode, each query will first be expanded (any calls to Projectable properties and methods will be replaced by their respective expression) before being handed off to EFCore. (This is similar to how LinqKit/LinqExpander/Expressionify works.) Because of this additional step, there is a small performance impact. Limited compatibility mode is smart about things and only expands the query after it has been accepted by EF. The expanded query will then be stored in the Query Cache. With Limited compatibility, you will likely see increased performance over EFCore without projectables.
97
+
There are two compatibility modes: Limited and Full (Default). Most of the time, limited compatibility mode is sufficient. However, if you are running into issues with failed query compilation, then you may want to stick with Full compatibility mode. With Full compatibility mode, each query will first be expanded (any calls to Projectable properties and methods will be replaced by their respective expression) before being handed off to EFCore. (This is similar to how LinqKit/LinqExpander/Expressionify works.) Because of this additional step, there is a small performance impact. Limited compatibility mode is smart about things and only expands the query after it has been accepted by EF. The expanded query will then be stored in the Query Cache. With Limited compatibility, you will likely see increased performance over EFCore without Projectables.
96
98
97
99
#### Can I call additional properties and methods from my Projectable properties and methods?
98
100
Yes, you can! Any projectable property/method can call into other properties and methods as long as those properties/methods are native to EFCore or marked with a Projectable attribute.
@@ -106,12 +108,12 @@ public static int Squared(this int i) => i * i;
106
108
Any call to squared given any int will perfectly translate to SQL.
107
109
108
110
#### How do I deal with nullable properties
109
-
Expressions and Lamdas are different and not equal. Expressions can only express a subset of valid CSharp statements that are allowed in lambda's and arrow functions. One obvious limitation is the null-conditional operator. Consider the following example:
111
+
Expressions and Lambdas are different and not equal. Expressions can only express a subset of valid C# statements that are allowed in lambda's and arrow functions. One obvious limitation is the null-conditional operator. Consider the following example:
This is a perfectly valid arrow function but it can't be translated directly to an expression tree. This Project will generate an error by default and suggest 2 solutions: Either you rewrite the function to explicitly check for nullables or you let the generator do that for you!
116
+
This is a perfectly valid arrow function, but it can't be translated directly to an expression tree. This Project will generate an error by default and suggest 2 solutions: Either you rewrite the function to explicitly check for nullables or you let the generator do that for you!
115
117
116
118
Starting from the official release of V2, we can now hint the generator in how to translate this arrow function to an expression tree. We can say:
117
119
```csharp
@@ -131,7 +133,7 @@ This will rewrite your expression to explicitly check for nullables. In the form
131
133
```
132
134
Note that using rewrite (not ignore) may increase the actual SQL query complexity being generated with some database providers such as SQL Server
133
135
134
-
#### Can I use projectables in any part of my query?
136
+
#### Can I use Projectables in any part of my query?
135
137
Certainly, consider the following example:
136
138
```csharp
137
139
publicclassUser
@@ -191,9 +193,203 @@ Both generate identical SQL. Block-bodied members support:
191
193
192
194
The generator will also detect and report side effects (assignments, method calls to non-projectable members, etc.) with precise error messages. See [Block-Bodied Members Documentation](docs/BlockBodiedMembers.md) for complete details.
193
195
196
+
#### Can I use `[Projectable]` on a constructor?
197
+
198
+
Yes! As of version 6.x, constructors can now be marked with `[Projectable]`. The generator will produce a member-init expression (`new T() { Prop = value, … }`) that EF Core can translate to a SQL projection.
199
+
200
+
**Requirements:**
201
+
- The class must expose an accessible **parameterless constructor** (public, internal, or protected-internal), because the generated code relies on `new T() { … }` syntax.
202
+
- If a parameterless constructor is missing, the generator reports **EFP0008**.
Unsupportedpatterns (e.g. positional/deconstructpatterns, variabledesignationsoutsideswitch arms) are reported as **EFP0007**.
194
390
195
391
#### How do I expand enum extension methods?
196
-
When you have an enum property and want to call an extension method on it (like getting a display name from a `[Display]` attribute), you can use the `ExpandEnumMethods` property on the `[Projectable]` attribute. This will expand the enum method call into a chain of ternary expressions for each enum value, allowing EF Core to translate it to SQL CASE expressions.
392
+
As of version 6.x, when you have an enum property and want to call an extension method on it (likegettingadisplaynamefroma `[Display]` attribute), you can use the `ExpandEnumMethods` property on the `[Projectable]` attribute. This will expand the enum method call into a chain of ternary expressions for each enum value, allowing EF Core to translate it to SQL CASE expressions.
197
393
198
394
```csharp
199
395
public enum OrderStatus
@@ -285,6 +481,7 @@ The `ExpandEnumMethods` feature supports:
0 commit comments