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: Use discriminator type to create the discriminator constant values #7448

Merged
merged 1 commit into from
Jan 31, 2017
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 @@ -89,7 +89,8 @@ var discriminatorColumn

var firstDiscriminatorValue
= Expression.Constant(
_relationalAnnotationProvider.For(concreteEntityTypes[0]).DiscriminatorValue);
_relationalAnnotationProvider.For(concreteEntityTypes[0]).DiscriminatorValue,
discriminatorColumn.Type);

var discriminatorPredicate
= Expression.Equal(discriminatorColumn, firstDiscriminatorValue);
Expand Down Expand Up @@ -142,7 +143,8 @@ var blockExpressions

var discriminatorValue
= Expression.Constant(
_relationalAnnotationProvider.For(concreteEntityType).DiscriminatorValue);
_relationalAnnotationProvider.For(concreteEntityType).DiscriminatorValue,
discriminatorColumn.Type);

materializer
= _entityMaterializerSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ var discriminatorColumn

var firstDiscriminatorValue
= Expression.Constant(
_relationalAnnotationProvider.For(concreteEntityTypes[0]).DiscriminatorValue);
_relationalAnnotationProvider.For(concreteEntityTypes[0]).DiscriminatorValue,
discriminatorColumn.Type);

var discriminatorPredicate
= Expression.Equal(discriminatorColumn, firstDiscriminatorValue);
Expand All @@ -324,7 +325,8 @@ var discriminatorPredicate
.Select(concreteEntityType
=> Expression.Constant(
_relationalAnnotationProvider
.For(concreteEntityType).DiscriminatorValue))
.For(concreteEntityType).DiscriminatorValue,
discriminatorColumn.Type))
.Aggregate(discriminatorPredicate, (current, discriminatorValue) =>
Expression.OrElse(
Expression.Equal(discriminatorColumn, discriminatorValue),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ var discriminatorPredicate
.Select(concreteEntityType =>
Expression.Equal(
discriminatorColumn,
Expression.Constant(relationalMetadataExtensionProvider.For(concreteEntityType).DiscriminatorValue)))
Expression.Constant(relationalMetadataExtensionProvider.For(concreteEntityType).DiscriminatorValue, discriminatorColumn.Type)))
.Aggregate((current, next) => Expression.OrElse(next, current));

handlerContext.SelectExpression.Predicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ var discriminatorPredicate
.Select(concreteEntityType =>
Expression.Equal(
discriminatorPropertyExpression,
Expression.Constant(_relationalAnnotationProvider.For(concreteEntityType).DiscriminatorValue)))
Expression.Constant(_relationalAnnotationProvider.For(concreteEntityType).DiscriminatorValue, discriminatorPropertyExpression.Type)))
.Aggregate((current, next) => Expression.OrElse(next, current));

return discriminatorPredicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public QueryBugsTest(SqlServerFixture fixture, ITestOutputHelper testOutputHelpe
//TestSqlLoggerFactory.CaptureOutput(testOutputHelper);
}

#region Bug6901

[Fact]
public void Left_outer_join_bug_6091()
{
Expand Down Expand Up @@ -124,6 +126,9 @@ public class Postcode
}
}

#endregion

#region Bug5481
[Fact]
public async Task Multiple_optional_navs_should_not_deadlock_bug_5481()
{
Expand Down Expand Up @@ -224,6 +229,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}

#endregion

[Fact]
public void Query_when_null_key_in_database_should_throw()
{
Expand Down Expand Up @@ -265,6 +272,8 @@ public class ZeroKey
}
}

#region Bug603

[Fact]
public async Task First_FirstOrDefault_ix_async_bug_603()
{
Expand Down Expand Up @@ -328,6 +337,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
private SqlServerTestStore CreateDatabase603()
=> CreateTestStore(() => new MyContext603(_options), null);

#endregion

#region Bugs925_926
[Fact]
public void Include_on_entity_with_composite_key_One_To_Many_bugs_925_926()
{
Expand Down Expand Up @@ -442,7 +454,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}

#region #7293
#endregion

#region Bug7293

[Fact]
public void GroupJoin_expansion_when_optional_nav_in_projection()
Expand Down Expand Up @@ -563,6 +577,8 @@ from user in users

#endregion

#region Bug963

[Fact]
public void Include_on_optional_navigation_One_To_Many_963()
{
Expand Down Expand Up @@ -701,6 +717,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}

#endregion

#region Bug1742
[Fact]
public void Compiler_generated_local_closure_produces_valid_parameter_name_1742()
=> Execute1742(new CustomerDetails_1742 { FirstName = "Foo", LastName = "Bar" });
Expand Down Expand Up @@ -734,6 +753,10 @@ public class CustomerDetails_1742
public string LastName { get; set; }
}

#endregion

#region Bug3758

[Fact]
public void Customer_collections_materialize_properly_3758()
{
Expand Down Expand Up @@ -884,7 +907,9 @@ private SqlServerTestStore CreateDatabase3758()

context.SaveChanges();
});
#endregion

#region Bug3409
[Fact]
public void ThenInclude_with_interface_navigations_3409()
{
Expand Down Expand Up @@ -995,6 +1020,10 @@ private SqlServerTestStore CreateDatabase3409()
context.SaveChanges();
});

#endregion

#region Bug3101

[Fact]
public virtual void Repro3101_simple_coalesce1()
{
Expand Down Expand Up @@ -1176,14 +1205,7 @@ from eRootJoined in RootEntities.DefaultIfEmpty()
}
}
}

private const string FileLineEnding = @"
";

protected virtual void ClearLog() => TestSqlLoggerFactory.Reset();

private static string Sql => TestSqlLoggerFactory.Sql.Replace(Environment.NewLine, FileLineEnding);


private SqlServerTestStore CreateDatabase3101()
=> CreateTestStore(() => new MyContext3101(_options),
context =>
Expand Down Expand Up @@ -1247,6 +1269,10 @@ public class Child3101
public string Name { get; set; }
}

#endregion

#region Bug5456

[Fact]
public virtual void Repro5456_include_group_join_is_per_query_context()
{
Expand Down Expand Up @@ -1414,6 +1440,72 @@ public class Comment5456
public Post5456 Blog { get; set; }
}

#endregion

#region Bug7359

[Fact]
public virtual void Discriminator_type_is_handled_correctly_in_materialization_bug_7359()
{
using (CreateDatabase7359())
{
using (var ctx = new MyContext7359(_options))
{
var query = ctx.Products.OfType<SpecialProduct>().ToList();

Assert.Equal(1, query.Count);
}
}
}

[Fact]
public virtual void Discriminator_type_is_handled_correctly_with_is_operator_bug_7359()
{
using (CreateDatabase7359())
{
using (var ctx = new MyContext7359(_options))
{
var query = ctx.Products.Where(p => p is SpecialProduct).ToList();

Assert.Equal(1, query.Count);
}
}
}

private class SpecialProduct : Product
{
}

private class MyContext7359 : DbContext
{
public MyContext7359(DbContextOptions options)
: base(options)
{
}

public DbSet<Product> Products { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SpecialProduct>();
modelBuilder.Entity<Product>()
.HasDiscriminator<int?>("Discriminator")
.HasValue(0)
.HasValue<SpecialProduct>(1);
}
}

private SqlServerTestStore CreateDatabase7359()
=> CreateTestStore(() => new MyContext7359(_options),
context =>
{
context.Add(new Product { Name = "Product1" });
context.Add(new SpecialProduct { Name = "SpecialProduct" });
context.SaveChanges();
});

#endregion

private DbContextOptions _options;

private SqlServerTestStore CreateTestStore<TContext>(
Expand All @@ -1438,5 +1530,12 @@ private SqlServerTestStore CreateTestStore<TContext>(
TestSqlLoggerFactory.Reset();
return testStore;
}

private const string FileLineEnding = @"
";

protected virtual void ClearLog() => TestSqlLoggerFactory.Reset();

private static string Sql => TestSqlLoggerFactory.Sql.Replace(Environment.NewLine, FileLineEnding);
}
}