Item https://entityframework.codeplex.com/workitem/1574 shows a huge performance difference between a query that contains a predicate that looks like this:
```
... OrganizationPeriodId == (Commons.CurrentUser.IsActivePeriodLoaded ? Commons.CurrentUser.ActivePeriodId : 0) ...
```
which translates to something like this:
```
... [Join7].[OrganizationPeriodId] = (CASE WHEN (@p__linq__0 = 1) THEN @p__linq__1 ELSE 0 END)
```
And just simply evaluating the expression into variable and passing the variable down to the query:
```
var orgPeriodId = (Commons.CurrentUser.IsActivePeriodLoaded ? Commons.CurrentUser.ActivePeriodId : 0);
... OrganizationPeriodId == orgPeriodId ...
```
which will translate into something like this, that is better conditioned for the server to leverage indexes:
```
... [Join7].[OrganizationPeriodId] = @p__linq__0
```
The sub-expression is not correlated to anything on the server, it is just a pure client-side, so this is an example of something that we could automatically funcletize and produce better performing query.
More details about client-side evaluation are found in [our spec](https://entityframework.codeplex.com/wikipage?title=Implicit%20boundaries%20in%20LINQ%20to%20Entities%20%28a.k.a.%20client-side%20evaluation%29&version=2).
```
... OrganizationPeriodId == (Commons.CurrentUser.IsActivePeriodLoaded ? Commons.CurrentUser.ActivePeriodId : 0) ...
```
which translates to something like this:
```
... [Join7].[OrganizationPeriodId] = (CASE WHEN (@p__linq__0 = 1) THEN @p__linq__1 ELSE 0 END)
```
And just simply evaluating the expression into variable and passing the variable down to the query:
```
var orgPeriodId = (Commons.CurrentUser.IsActivePeriodLoaded ? Commons.CurrentUser.ActivePeriodId : 0);
... OrganizationPeriodId == orgPeriodId ...
```
which will translate into something like this, that is better conditioned for the server to leverage indexes:
```
... [Join7].[OrganizationPeriodId] = @p__linq__0
```
The sub-expression is not correlated to anything on the server, it is just a pure client-side, so this is an example of something that we could automatically funcletize and produce better performing query.
More details about client-side evaluation are found in [our spec](https://entityframework.codeplex.com/wikipage?title=Implicit%20boundaries%20in%20LINQ%20to%20Entities%20%28a.k.a.%20client-side%20evaluation%29&version=2).