From 06402ffef4c1cb213275eabbd72481c69c189d29 Mon Sep 17 00:00:00 2001 From: Nathan Buuck Date: Fri, 28 Aug 2020 22:14:21 -0400 Subject: [PATCH 1/2] doc: ordering issue in FromSql --- entity-framework/core/querying/raw-sql.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/entity-framework/core/querying/raw-sql.md b/entity-framework/core/querying/raw-sql.md index a0eb997d6c..e4aa275e96 100644 --- a/entity-framework/core/querying/raw-sql.md +++ b/entity-framework/core/querying/raw-sql.md @@ -50,6 +50,10 @@ You can also construct a DbParameter and supply it as a parameter value. Since a [!code-csharp[Main](../../../samples/core/Querying/RawSQL/Sample.cs#FromSqlRawStoredProcedureNamedSqlParameter)] +> [!NOTE] +> **Parameter Ordering** +> When passing multiple `SqlParameter`s, the ordering in the SQL string must match the order of the parameters in the stored procedure's definition. Failing to do this can result in type conversion exceptions or unexpected behavior when the procedure is executed because Entity Framework Core will apply the order of the `SqlParameter[]` array literally and will not reorder them to match the order defined in the stored procedure's definition. This behavior is not typical of stored procedures when using named parameters and is seemingly specific to `FromSql()`. + ## Composing with LINQ You can compose on top of the initial raw SQL query using LINQ operators. EF Core will treat it as subquery and compose over it in the database. The following example uses a raw SQL query that selects from a Table-Valued Function (TVF). And then composes on it using LINQ to do filtering and sorting. From b951dd88e14754e5e6d1db7151d5afcc34974af4 Mon Sep 17 00:00:00 2001 From: Nathan Buuck Date: Sun, 6 Sep 2020 22:37:33 -0400 Subject: [PATCH 2/2] Accept revision from @JeremyLikness Co-authored-by: Jeremy Likness --- entity-framework/core/querying/raw-sql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-framework/core/querying/raw-sql.md b/entity-framework/core/querying/raw-sql.md index e4aa275e96..dd349a415b 100644 --- a/entity-framework/core/querying/raw-sql.md +++ b/entity-framework/core/querying/raw-sql.md @@ -52,7 +52,7 @@ You can also construct a DbParameter and supply it as a parameter value. Since a > [!NOTE] > **Parameter Ordering** -> When passing multiple `SqlParameter`s, the ordering in the SQL string must match the order of the parameters in the stored procedure's definition. Failing to do this can result in type conversion exceptions or unexpected behavior when the procedure is executed because Entity Framework Core will apply the order of the `SqlParameter[]` array literally and will not reorder them to match the order defined in the stored procedure's definition. This behavior is not typical of stored procedures when using named parameters and is seemingly specific to `FromSql()`. +> Entity Framework Core passes parameters based on the order of the `SqlParameter[]` array. When passing multiple `SqlParameter`s, the ordering in the SQL string must match the order of the parameters in the stored procedure's definition. Failure to do this may result in type conversion exceptions and/or unexpected behavior when the procedure is executed. ## Composing with LINQ