Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
Closes #13517
  • Loading branch information
roji committed Sep 28, 2019
1 parent 732d578 commit 31eed90
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6942,6 +6942,82 @@ private class DbGame

#endregion

#region Issue13517

[Fact]
public void Query_filter_with_pk_fk_optimization_bug_13517()
{
using var _ = CreateDatabase13517();
using var context = new BugContext13517(_options);

context.Entities.Select(s =>
new BugEntityDto13517
{
Id = s.Id,
RefEntity = s.RefEntity == null
? null
: new BugRefEntityDto13517 { Id = s.RefEntity.Id, Public = s.RefEntity.Public },
RefEntityId = s.RefEntityId
}).Single(p => p.Id == 1);
}

private SqlServerTestStore CreateDatabase13517()
=> CreateTestStore(
() => new BugContext13517(_options),
context =>
{
var refEntity = new BugRefEntity13517 { Public = false };
context.RefEntities.Add(refEntity);
context.Entities.Add(new BugEntity13517 { RefEntity = refEntity });
context.SaveChanges();

ClearLog();
});

public class BugEntity13517
{
public int Id { get; set; }
public int? RefEntityId { get; set; }
public BugRefEntity13517 RefEntity { get; set; }
}

public class BugRefEntity13517
{
public int Id { get; set; }
public bool Public { get; set; }
}

public class BugEntityDto13517
{
public int Id { get; set; }
public int? RefEntityId { get; set; }
public BugRefEntityDto13517 RefEntity { get; set; }
}

public class BugRefEntityDto13517
{
public int Id { get; set; }
public bool Public { get; set; }
}

private class BugContext13517 : DbContext
{
public DbSet<BugEntity13517> Entities { get; set; }
public DbSet<BugRefEntity13517> RefEntities { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BugRefEntity13517>().HasQueryFilter(f => f.Public == true);
}

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

#endregion

private DbContextOptions _options;

private SqlServerTestStore CreateTestStore<TContext>(
Expand Down

0 comments on commit 31eed90

Please sign in to comment.