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

Exclude Object when checking for DbContext in query filters #18770

Merged
merged 1 commit into from
Nov 11, 2019
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 @@ -349,11 +349,10 @@ public ContextParameterReplacingExpressionVisitor(Type contextType)
public ParameterExpression ContextParameterExpression { get; }

public override Expression Visit(Expression expression)
{
return expression?.Type.GetTypeInfo().IsAssignableFrom(_contextType) == true
=> expression?.Type != typeof(object)
&& expression?.Type.GetTypeInfo().IsAssignableFrom(_contextType) == true
? ContextParameterExpression
: base.Visit(expression);
}
}

private static Expression RemoveConvert(Expression expression)
Expand Down
51 changes: 51 additions & 0 deletions test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7361,6 +7361,57 @@ public BugContext18087(DbContextOptions options)

#endregion

#region Issue18759

[ConditionalFact]
public void Query_filter_with_null_constant()
{
using var _ = CreateDatabase18759();
using var context = new BugContext18759(_options);

var people = context.People.ToList();

AssertSql(
@"SELECT [p].[Id], [p].[UserDeleteId]
FROM [People] AS [p]
LEFT JOIN [User18759] AS [u] ON [p].[UserDeleteId] = [u].[Id]
WHERE [u].[Id] IS NOT NULL");
}

private SqlServerTestStore CreateDatabase18759()
=> CreateTestStore(
() => new BugContext18759(_options),
context =>
{
ClearLog();
});

public class Person18759
{
public int Id { get; set; }
public User18759 UserDelete { get; set; }
}

public class User18759
roji marked this conversation as resolved.
Show resolved Hide resolved
{
public int Id { get; set; }
}

private class BugContext18759 : DbContext
{
public DbSet<Person18759> People { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Person18759>().HasQueryFilter(p => p.UserDelete != null);

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

#endregion Issue18759
roji marked this conversation as resolved.
Show resolved Hide resolved

private DbContextOptions _options;

private SqlServerTestStore CreateTestStore<TContext>(
Expand Down