From b266e4cb718053238b54ffc7d9a009576a887664 Mon Sep 17 00:00:00 2001 From: Jimmy Bogard Date: Fri, 14 Oct 2022 08:04:56 -0500 Subject: [PATCH 1/2] Emphasized the ProjectTo method call location --- docs/Queryable-Extensions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Queryable-Extensions.md b/docs/Queryable-Extensions.md index 0908790b16..f3e5cec6f2 100644 --- a/docs/Queryable-Extensions.md +++ b/docs/Queryable-Extensions.md @@ -56,9 +56,9 @@ public List GetLinesForOrder(int orderId) ``` The `.ProjectTo()` will tell AutoMapper's mapping engine to emit a `select` clause to the IQueryable that will inform entity framework that it only needs to query the Name column of the Item table, same as if you manually projected your `IQueryable` to an `OrderLineDTO` with a `Select` clause. - -`ProjectTo` must be the last call in the chain. ORMs work with entities, not DTOs. So apply any filtering and sorting on entities and, as the last step, project to DTOs. - + +**`ProjectTo` must be the last call in the LINQ method chain. ORMs work with entities, not DTOs. Apply any filtering and sorting on entities and, as the last step, project to DTOs. Query providers are highly complex and making the `ProjectTo` call last ensures the query provider works as closely as designed to build valid queries against the underlying query target (SQL, Mongo QL etc.).** + Note that for this feature to work, all type conversions must be explicitly handled in your Mapping. For example, you can not rely on the `ToString()` override of the `Item` class to inform entity framework to only select from the `Name` column, and any data type changes, such as `Double` to `Decimal` must be explicitly handled as well. ### The instance API @@ -208,7 +208,7 @@ Not all mapping options can be supported, as the expression generated must be in * ConvertUsing (Expression-based) * Ignore * NullSubstitute -* Value transformers +* Value transformers * IncludeMembers Not supported: From fe7f5ec39e33f77a7573fbdb138c1a22c81bb14b Mon Sep 17 00:00:00 2001 From: Jimmy Bogard Date: Mon, 16 Jan 2023 09:32:56 -0600 Subject: [PATCH 2/2] Update Queryable-Extensions.md --- docs/Queryable-Extensions.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/Queryable-Extensions.md b/docs/Queryable-Extensions.md index f3e5cec6f2..e1e2e24fe7 100644 --- a/docs/Queryable-Extensions.md +++ b/docs/Queryable-Extensions.md @@ -57,7 +57,9 @@ public List GetLinesForOrder(int orderId) The `.ProjectTo()` will tell AutoMapper's mapping engine to emit a `select` clause to the IQueryable that will inform entity framework that it only needs to query the Name column of the Item table, same as if you manually projected your `IQueryable` to an `OrderLineDTO` with a `Select` clause. -**`ProjectTo` must be the last call in the LINQ method chain. ORMs work with entities, not DTOs. Apply any filtering and sorting on entities and, as the last step, project to DTOs. Query providers are highly complex and making the `ProjectTo` call last ensures the query provider works as closely as designed to build valid queries against the underlying query target (SQL, Mongo QL etc.).** +### Query Provider Limitations + +`ProjectTo` must be the last call in the LINQ method chain. ORMs work with entities, not DTOs. Apply any filtering and sorting on entities and, as the last step, project to DTOs. Query providers are highly complex and making the `ProjectTo` call last ensures the query provider works as closely as designed to build valid queries against the underlying query target (SQL, Mongo QL etc.). Note that for this feature to work, all type conversions must be explicitly handled in your Mapping. For example, you can not rely on the `ToString()` override of the `Item` class to inform entity framework to only select from the `Name` column, and any data type changes, such as `Double` to `Decimal` must be explicitly handled as well.