Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Fix bug in FromSqlExpression.Equals #21833

Merged
1 commit merged into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public override bool Equals(object obj)

private bool Equals(FromSqlExpression fromSqlExpression)
=> base.Equals(fromSqlExpression)
&& string.Equals(Sql, fromSqlExpression.Sql);
&& string.Equals(Sql, fromSqlExpression.Sql)
&& ExpressionEqualityComparer.Instance.Equals(Arguments, fromSqlExpression.Arguments);

/// <inheritdoc />
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Sql);
Expand Down
73 changes: 73 additions & 0 deletions test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8034,6 +8034,79 @@ private SqlServerTestStore CreateDatabase21768()
});

#endregion

#region Issue19206

[ConditionalFact]
public virtual void From_sql_expression_compares_correctly()
{
using (CreateDatabase19206())
{
using var context = new MyContext19206(_options);
var query = from t1 in context.Tests.FromSqlInterpolated($"Select * from Tests Where Type = {TestType19206.Unit}")
from t2 in context.Tests.FromSqlInterpolated($"Select * from Tests Where Type = {TestType19206.Integration}")
select new { t1, t2 };

var result = query.ToList();

var item = Assert.Single(result);
Assert.Equal(TestType19206.Unit, item.t1.Type);
Assert.Equal(TestType19206.Integration, item.t2.Type);

AssertSql(
@"p0='0'
p1='1'

SELECT [t].[Id], [t].[Type], [t0].[Id], [t0].[Type]
FROM (
Select * from Tests Where Type = @p0
) AS [t]
CROSS JOIN (
Select * from Tests Where Type = @p1
) AS [t0]");
}
}

public class Test19206
{
public int Id { get; set; }
public TestType19206 Type { get; set; }
}

public enum TestType19206
{
Unit,
Integration,
}

private class MyContext19206 : DbContext
{
public DbSet<Test19206> Tests { get; set; }

public MyContext19206(DbContextOptions options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}

private SqlServerTestStore CreateDatabase19206()
=> CreateTestStore(
() => new MyContext19206(_options),
context =>
{
context.Add(new Test19206 { Type = TestType19206.Unit });
context.Add(new Test19206 { Type = TestType19206.Integration });
context.SaveChanges();

ClearLog();
});

#endregion

private DbContextOptions _options;

private SqlServerTestStore CreateTestStore<TContext>(
Expand Down