Skip to content

Commit 80a9cff

Browse files
committed
Update docs and nuget package description
1 parent 1cd4f6a commit 80a9cff

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</p>
44

55
# QueryableValues [![CI/CD Workflow](https://github.com/yv989c/BlazarTech.QueryableValues/actions/workflows/ci-workflow.yml/badge.svg)](https://github.com/yv989c/BlazarTech.QueryableValues/actions/workflows/ci-workflow.yml)
6-
This library allows you to efficiently compose an [IEnumerable\<T\>] in your [Entity Framework Core] queries when using the [SQL Server Database Provider]. This is accomplished by using the `AsQueryableValues` extension method available on the [DbContext] class. Everything is evaluated on the server with a single round trip, in a way that preserves the querys [execution plan], even when the values behind the [IEnumerable\<T\>] are changed on subsequent executions.
6+
This library allows you to efficiently compose an [IEnumerable\<T\>] in your [Entity Framework Core] queries when using the [SQL Server Database Provider]. This is accomplished by using the `AsQueryableValues` extension method available on the [DbContext] class. Everything is evaluated on the server with a single round trip, in a way that preserves the query's [execution plan], even when the values behind the [IEnumerable\<T\>] are changed on subsequent executions.
77

88
The supported types for `T` are:
99
- Simple Type: [Byte], [Int16], [Int32], [Int64], [Decimal], [Single], [Double], [DateTime], [DateTimeOffset], [Guid], [Char], and [String].
@@ -22,7 +22,7 @@ It provides a solution to the following long standing [EF Core issue](https://gi
2222
## Getting Started
2323

2424
### Installation
25-
QueryableValues is distributed as a [NuGet Package]. The major version number of this library is aligned with the version of [Entity Framework Core] by which its supported (e.g. If you are using EF Core 5, then you must use version 5 of QueryableValues).
25+
QueryableValues is distributed as a [NuGet Package]. The major version number of this library is aligned with the version of [Entity Framework Core] by which it's supported (e.g. If you are using EF Core 5, then you must use version 5 of QueryableValues).
2626

2727
Please choose the appropriate command below to install it using the NuGet Package Manager Console window in Visual Studio:
2828

@@ -144,8 +144,8 @@ var myQuery2 =
144144
#### Complex Type Example
145145
```c#
146146
// Performance Tip:
147-
// If your IEnumerable<T> variable’s item type has many properties,
148-
// project only the ones you need to a new variable and use it in your query.
147+
// If your IEnumerable<T> item type (T) has many properties, project only
148+
// the ones you need to a new variable and use it in your query.
149149
var projectedItems = items.Select(i => new { i.CategoryId, i.ColorName });
150150

151151
var myQuery =
@@ -158,7 +158,7 @@ var myQuery =
158158
};
159159
```
160160
**About Complex Types**
161-
> :warning: All the data provided by this type is transmitted to the server; therefore, ensure that it only contains the properties you need for your query. Not following this recommendation will degrade the querys performance.
161+
> :warning: All the data provided by this type is transmitted to the server; therefore, ensure that it only contains the properties you need for your query. Not following this recommendation will degrade the query's performance.
162162
163163
> :warning: There is a limit of up to 10 properties for any given simple type (e.g. cannot have more than 10 [Int32] properties). Exceeding that limit will cause an exception and may also suggest that you should rethink your strategy.
164164
@@ -180,9 +180,9 @@ var myQuery = dbContext.MyEntities
180180
i.PropC
181181
});
182182
```
183-
The previous query will yield the expected results, but theres a catch. If the sequence of values in our list *is different* on every execution, the underline SQL query will be built in a way thats not optimal for SQL Servers query engine. Wasting system resources like CPU, memory, IO, and potentially affecting other queries in the instance.
183+
The previous query will yield the expected results, but there's a catch. If the sequence of values in our list *is different* on every execution, the underline SQL query will be built in a way that's not optimal for SQL Server's query engine. Wasting system resources like CPU, memory, IO, and potentially affecting other queries in the instance.
184184

185-
Lets take a look at the following query and the SQL that is generated by the [SQL Server Database Provider] as of version 5.0.11 when the query is materialized:
185+
Let's take a look at the following query and the SQL that is generated by the [SQL Server Database Provider] as of version 5.0.11 when the query is materialized:
186186

187187
```c#
188188
var listOfValues = new List<int> { 1, 2, 3 };
@@ -207,20 +207,20 @@ WHERE [m].[MyEntityID] IN (1, 2, 3) OR ([m].[PropB] = @__p_1)',N'@__p_1 bigint',
207207
```
208208
Here we can observe that the values in our list are being hardcoded as part of the SQL statement provided to [sp_executesql] as opposed to them being injected via a parameter, as is the case for our other variable holding the value 100.
209209

210-
Now, lets add another item to the list of values and execute the query again:
210+
Now, let's add another item to the list of values and execute the query again:
211211
```tsql
212212
exec sp_executesql N'SELECT [m].[MyEntityID], [m].[PropA]
213213
FROM [dbo].[MyEntity] AS [m]
214214
WHERE [m].[MyEntityID] IN (1, 2, 3, 4) OR ([m].[PropB] = @__p_1)',N'@__p_1 bigint',@__p_1=100
215215
```
216-
As we can see, a new SQL statement was generated just because we modified the list thats being used in our `Where` predicate. This has the detrimental effect that a previously cached execution plan cannot be reused, forcing SQL Servers query engine to compute a new [execution plan] *every time* it is provided with a SQL statement that it hasnt seen before and increasing the likelihood of flushing other plans in the process.
216+
As we can see, a new SQL statement was generated just because we modified the list that's being used in our `Where` predicate. This has the detrimental effect that a previously cached execution plan cannot be reused, forcing SQL Server's query engine to compute a new [execution plan] *every time* it is provided with a SQL statement that it hasn't seen before and increasing the likelihood of flushing other plans in the process.
217217

218218
## Enter AsQueryableValues 🙌
219219
![Parameterize All the Things](/docs/images/parameterize-all-the-things.jpg)
220220

221221
This library provides you with the `AsQueryableValues` extension method made available on the [DbContext] class. It solves the problem explained above by allowing you to build a query that will generate a SQL statement for [sp_executesql] that will remain constant execution after execution, allowing SQL Server to do its best every time by using a previously cached [execution plan]. This will speed up your query on subsequent executions, and conserve system resources.
222222

223-
Lets take a look at the following query making use of this method, which is functionally equivalent to the previous example:
223+
Let's take a look at the following query making use of this method, which is functionally equivalent to the previous example:
224224
```c#
225225
var myQuery = dbContext.MyEntities
226226
.Where(i =>
@@ -246,7 +246,7 @@ WHERE EXISTS (
246246
) AS [q]
247247
WHERE [q].[V] = [m].[MyEntityID]) OR ([m].[PropB] = @__p_1)',N'@p0 xml,@__p_1 bigint',@p0=@p3,@__p_1=100
248248
```
249-
Now, lets add another item to the list of values and execute the query again:
249+
Now, let's add another item to the list of values and execute the query again:
250250
```tsql
251251
declare @p3 xml
252252
set @p3=convert(xml,N'<R><V>1</V><V>2</V><V>3</V><V>4</V></R>')
@@ -262,19 +262,19 @@ WHERE EXISTS (
262262
Great! The SQL statement provided to [sp_executesql] remains constant. In this case SQL Server can reuse the [execution plan] from the previous execution.
263263

264264
## The Numbers 📊
265-
You dont have to take my word for it! Lets see a trace of whats going on under the hood when both of these queries are executed multiple times, adding a new value to the list after each execution. First, five executions of the one making direct use of the [Contains][ContainsEnumerable] LINQ method (orange), and then five executions of the second one making use of the `AsQueryableValues` extension method on the [DbContext] (green):
265+
You don't have to take my word for it! Let's see a trace of what's going on under the hood when both of these queries are executed multiple times, adding a new value to the list after each execution. First, five executions of the one making direct use of the [Contains][ContainsEnumerable] LINQ method (orange), and then five executions of the second one making use of the `AsQueryableValues` extension method on the [DbContext] (green):
266266

267267
![Trace](/docs/images/as-queryable-trace.png)
268268
<sup>Queries executed against SQL Server 2017 Express (14.0.2037) running on a resource constrained laptop.</sup>
269269

270270
As expected, none of the queries in the orange section hit the cache. On the other hand, after the first query in the green section, all the subsequent ones hit the cache and consumed fewer resources.
271271

272-
Now, focus your attention to the first query of the green section. Here you can observe that theres a cost associated with this technique, but this cost can be offset in the long run, especially when your queries are not trivial like the ones in these examples.
272+
Now, focus your attention to the first query of the green section. Here you can observe that there's a cost associated with this technique, but this cost can be offset in the long run, especially when your queries are not trivial like the ones in these examples.
273273

274274
## What Makes This Work? 🤓
275-
QueryableValues makes use of the XML parsing capabilities in SQL Server, which are available in all the supported versions of SQL Server to date. The provided sequence of values are serialized as XML and embedded in the underlying SQL query using a native XML parameter, then it uses SQL Servers XML type methods to project the query in a way that can be mapped by [Entity Framework Core].
275+
QueryableValues makes use of the XML parsing capabilities in SQL Server, which are available in all the supported versions of SQL Server to date. The provided sequence of values are serialized as XML and embedded in the underlying SQL query using a native XML parameter, then it uses SQL Server's XML type methods to project the query in a way that can be mapped by [Entity Framework Core].
276276

277-
This is a technique that I have not seen being used by other popular libraries that aim to solve this problem. It is superior from a latency standpoint because it resolves the query with a single round trip to the database and most importantly, it preserves the querys [execution plan] even when the content of the XML is changed.
277+
This is a technique that I have not seen being used by other popular libraries that aim to solve this problem. It is superior from a latency standpoint because it resolves the query with a single round trip to the database and most importantly, it preserves the query's [execution plan] even when the content of the XML is changed.
278278

279279
## One More Thing 👀
280280
The `AsQueryableValues` extension method allows you to treat a sequence of values as you normally would if these were another entity in your [DbContext]. The type returned by the extension is an [IQueryable\<T\>] that can be composed with other entities in your query.

docs/README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
# QueryableValues
22

3-
This library allows us to efficiently compose an [IEnumerable<T>] in our [Entity Framework Core] queries when using the [SQL Server Database Provider]. This is done by using the `AsQueryableValues` extension method that is made available on the [DbContext] class. Everything is evaluated on the server with a single roundtrip, in a way that preserves the query's [execution plan], even when the values behind the [IEnumerable<T>] are changed on subsequent executions.
3+
This library allows you to efficiently compose an [IEnumerable<T>] in your [Entity Framework Core] queries when using the [SQL Server Database Provider]. This is accomplished by using the `AsQueryableValues` extension method available on the [DbContext] class. Everything is evaluated on the server with a single round trip, in a way that preserves the query's [execution plan], even when the values behind the [IEnumerable<T>] are changed on subsequent executions.
44

55
The supported types for `T` are:
6-
- Simple Type: [Int32], [Int64], [Decimal], [Double], [DateTime], [DateTimeOffset], [Guid], and [String].
6+
- Simple Type: [Byte], [Int16], [Int32], [Int64], [Decimal], [Single], [Double], [DateTime], [DateTimeOffset], [Guid], [Char], and [String].
77
- Complex Type:
88
- Can be an anonymous type.
9-
- Can be a user defined class or struct, with read/write properties and a public constructor.
10-
- Must have one or more simple type properties.
9+
- Can be a user-defined class or struct with read/write properties and a public constructor.
10+
- Must have one or more simple type properties, including [Boolean].
1111

1212
For a detailed explanation, please continue reading [here][readme-background].
1313

14-
## When Should I Use It?
15-
The `AsQueryableValues` extension method is intended for queries that are dependent on a *non-constant* sequence of external values. In this case, the underline SQL query will be efficient on subsequent executions.
14+
## When Should You Use It?
15+
The `AsQueryableValues` extension method is intended for queries that are dependent upon a *non-constant* sequence of external values. In such cases, the underlying SQL query will be efficient on subsequent executions.
1616

17-
It provides a solution to the following long standing EF Core [issue](https://github.com/dotnet/efcore/issues/13617) and enables other currently unsupported scenarios; like the ability to efficiently create joins with in-memory data.
17+
It provides a solution to the following long standing [EF Core issue](https://github.com/dotnet/efcore/issues/13617) and enables other currently unsupported scenarios; like the ability to efficiently create joins with in-memory data.
1818

1919
## Getting Started
2020

2121
### Installation
22-
QueryableValues is distributed as a [NuGet Package]. The major version number of this library is aligned with the version of [Entity Framework Core] that's supported by it; for example, if you are using EF Core 5, then you must use version 5 of QueryableValues.
22+
QueryableValues is distributed as a [NuGet Package]. The major version number of this library is aligned with the version of [Entity Framework Core] by which it's supported (e.g. If you are using EF Core 5, then you must use version 5 of QueryableValues).
2323

2424
Please choose the appropriate command below to install it using the NuGet Package Manager Console window in Visual Studio:
2525

2626
EF Core | Command
2727
:---: | ---
28-
3.x | `Install-Package BlazarTech.QueryableValues.SqlServer -Version 3.2.0`
29-
5.x | `Install-Package BlazarTech.QueryableValues.SqlServer -Version 5.2.0`
30-
6.x | `Install-Package BlazarTech.QueryableValues.SqlServer -Version 6.2.0`
28+
3.x | `Install-Package BlazarTech.QueryableValues.SqlServer -Version 3.3.0`
29+
5.x | `Install-Package BlazarTech.QueryableValues.SqlServer -Version 5.3.0`
30+
6.x | `Install-Package BlazarTech.QueryableValues.SqlServer -Version 6.3.0`
3131

3232
### Configuration
33-
Look for the place in your code where you are setting up your [DbContext] and calling the [UseSqlServer] extension method, then use a lambda expression to access the `SqlServerDbContextOptionsBuilder` provided by it. It is on this builder that you must call the `UseQueryableValues` extension method, as shown in the following simplified examples:
33+
Look for the place in your code where you are setting up your [DbContext] and calling the [UseSqlServer] extension method, then use a lambda expression to access the `SqlServerDbContextOptionsBuilder` provided by it. It is on this builder that you must call the `UseQueryableValues` extension method as shown in the following simplified examples:
3434

3535
When using the `OnConfiguring` method inside your [DbContext]:
3636
```c#
@@ -71,13 +71,13 @@ public class Startup
7171
}
7272
```
7373

74-
### How Do I Use It?
75-
The `AsQueryableValues` extension method is provided by the `BlazarTech.QueryableValues` namespace, therefore, you must add the following `using` directive to your source code file in order for it to appear as a method of your [DbContext] instance:
74+
### How Do You Use It?
75+
The `AsQueryableValues` extension method is provided by the `BlazarTech.QueryableValues` namespace; therefore, you must add the following `using` directive to your source code file for it to appear as a method of your [DbContext] instance:
7676
```
7777
using BlazarTech.QueryableValues;
7878
```
7979

80-
Below you can find a few examples composing a query using the values provided by an [IEnumerable<T>].
80+
Below are a few examples composing a query using the values provided by an [IEnumerable<T>].
8181

8282
#### Simple Type Examples
8383
Using the [Contains][ContainsQueryable] LINQ method:
@@ -138,10 +138,11 @@ var myQuery2 =
138138
i.PropA
139139
});
140140
```
141-
#### Complex Type Examples
141+
#### Complex Type Example
142142
```c#
143-
// If your IEnumerable<T> variable's item type is a complex type with many properties,
144-
// project only what you need to a new variable and use it in your query.
143+
// Performance Tip:
144+
// If your IEnumerable<T> item type (T) has many properties, project only
145+
// the ones you need to a new variable and use it in your query.
145146
var projectedItems = items.Select(i => new { i.CategoryId, i.ColorName });
146147

147148
var myQuery =
@@ -154,12 +155,12 @@ var myQuery =
154155
};
155156
```
156157
**About Complex Types**
157-
> :warning: All the data provided by this type is transmitted to the server, therefore, ensure that it only contains the properties that you need for your query. Not following this recommendation will degrade the query's performance.
158+
> :warning: All the data provided by this type is transmitted to the server; therefore, ensure that it only contains the properties you need for your query. Not following this recommendation will degrade the query's performance.
158159
159-
> :warning: There is a limit of up to ten properties for any given simple type (e.g., cannot have more than ten [Int32] properties). Exceeding that limit will cause an exception and may also be a sign that you should rethink your strategy.
160+
> :warning: There is a limit of up to 10 properties for any given simple type (e.g. cannot have more than 10 [Int32] properties). Exceeding that limit will cause an exception and may also suggest that you should rethink your strategy.
160161
161-
## Do You Want to Know More? 📚
162-
Please take a look at the repository [here](https://github.com/yv989c/BlazarTech.QueryableValues).
162+
## Do You Want To Know More? 📚
163+
Please take a look at the [repository](https://github.com/yv989c/BlazarTech.QueryableValues).
163164

164165

165166
[Entity Framework Core]: https://docs.microsoft.com/en-us/ef/core/
@@ -176,11 +177,16 @@ Please take a look at the repository [here](https://github.com/yv989c/BlazarTech
176177
[NuGet Package]: https://www.nuget.org/packages/BlazarTech.QueryableValues.SqlServer/
177178
[readme-background]: https://github.com/yv989c/BlazarTech.QueryableValues#background-
178179
[execution plan]: https://docs.microsoft.com/en-us/sql/relational-databases/query-processing-architecture-guide?#execution-plan-caching-and-reuse
180+
[Boolean]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean
181+
[Byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte
182+
[Int16]: https://docs.microsoft.com/en-us/dotnet/api/system.int16
179183
[Int32]: https://docs.microsoft.com/en-us/dotnet/api/system.int32
180184
[Int64]: https://docs.microsoft.com/en-us/dotnet/api/system.int64
181185
[Decimal]: https://docs.microsoft.com/en-us/dotnet/api/system.decimal
186+
[Single]: https://docs.microsoft.com/en-us/dotnet/api/system.single
182187
[Double]: https://docs.microsoft.com/en-us/dotnet/api/system.double
183188
[DateTime]: https://docs.microsoft.com/en-us/dotnet/api/system.datetime
184189
[DateTimeOffset]: https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset
185190
[Guid]: https://docs.microsoft.com/en-us/dotnet/api/system.guid
191+
[Char]: https://docs.microsoft.com/en-us/dotnet/api/system.char
186192
[String]: https://docs.microsoft.com/en-us/dotnet/api/system.string

0 commit comments

Comments
 (0)