Skip to content

Commit

Permalink
Query: Improve detection of non-composed FromSql
Browse files Browse the repository at this point in the history
Resolves #16079
  • Loading branch information
smitpatel committed Mar 21, 2020
1 parent 7166201 commit 9dfadbc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public bool IsNonComposedFromSql()
&& Tables[0] is FromSqlExpression fromSql
&& Projection.All(
pe => pe.Expression is ColumnExpression column
&& string.Equals(fromSql.Alias, column.Table.Alias, StringComparison.OrdinalIgnoreCase));
&& string.Equals(fromSql.Alias, column.Table.Alias, StringComparison.OrdinalIgnoreCase))
&& _projectionMapping.TryGetValue(new ProjectionMember(), out var mapping)
&& mapping.Type == typeof(Dictionary<IProperty, int>);

public void ApplyProjection()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ public virtual async Task From_sql_queryable_stored_procedure_projection(bool as
.FromSqlRaw(TenMostExpensiveProductsSproc, GetTenMostExpensiveProductsParameters())
.Select(mep => mep.TenMostExpensiveProducts);

var actual = async
? await query.ToArrayAsync()
: query.ToArray();

Assert.Equal(10, actual.Length);
Assert.Contains(actual, r => r == "Côte de Blaye");
Assert.Equal(
RelationalStrings.FromSqlNonComposable,
(async
? await Assert.ThrowsAsync<InvalidOperationException>(() => query.ToArrayAsync())
: Assert.Throws<InvalidOperationException>(() => query.ToArray())).Message);
}

[ConditionalTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,14 @@ public override void FromSqlRaw_queryable_simple_projection_composed()
{
base.FromSqlRaw_queryable_simple_projection_composed();

// issue #16079
// AssertSql(
// @"SELECT [p].[ProductName]
//FROM (
// SELECT *
// FROM ""Products""
// WHERE ""Discontinued"" <> CAST(1 AS bit)
// AND ((""UnitsInStock"" + ""UnitsOnOrder"") < ""ReorderLevel"")
//) AS [p]");
AssertSql(
@"SELECT [p].[ProductName]
FROM (
SELECT *
FROM ""Products""
WHERE ""Discontinued"" <> CAST(1 AS bit)
AND ((""UnitsInStock"" + ""UnitsOnOrder"") < ""ReorderLevel"")
) AS [p]");
}

public override void FromSqlRaw_queryable_simple_include()
Expand Down Expand Up @@ -717,7 +716,10 @@ public override void FromSqlInterpolated_parameterization_issue_12213()
AssertSql(
@"p0='10300'
SELECT * FROM ""Orders"" WHERE ""OrderID"" >= @p0",
SELECT [o].[OrderID]
FROM (
SELECT * FROM ""Orders"" WHERE ""OrderID"" >= @p0
) AS [o]",
//
@"@__max_0='10400'
p0='10300'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ public override async Task From_sql_queryable_stored_procedure_with_tag(bool asy
[dbo].[Ten Most Expensive Products]");
}

public override async Task From_sql_queryable_stored_procedure_projection(bool async)
{
await base.From_sql_queryable_stored_procedure_projection(async);

AssertSql("[dbo].[Ten Most Expensive Products]");
}

public override async Task From_sql_queryable_stored_procedure_with_parameter(bool async)
{
await base.From_sql_queryable_stored_procedure_with_parameter(async);
Expand Down

0 comments on commit 9dfadbc

Please sign in to comment.