Skip to content

Commit

Permalink
Add regression test for issue#20046
Browse files Browse the repository at this point in the history
Resolved by #19377
Issue fixed since cast to base type is removed by nav expansion as it is redundant

Resolves #20046
  • Loading branch information
smitpatel committed Mar 10, 2020
1 parent a676fae commit 1d40504
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@ public virtual void FromSql_on_derived()
context.Set<Eagle>().FromSqlRaw(NormalizeDelimitersInRawString("select * from [Animal]")).ToList();
}

[ConditionalFact]
public virtual void Casting_to_base_type_joining_with_query_type_works()
{
using var context = CreateContext();
var query = context.Set<Eagle>();

GetEntityWithAuditHistoryQuery(context, query);
}

private void GetEntityWithAuditHistoryQuery<T>(InheritanceContext context, IQueryable<T> query)
where T : Animal
{
var queryTypeQuery = context.Set<AnimalQuery>().FromSqlRaw(NormalizeDelimitersInRawString("Select * from [Animal]"));

var animalQuery = query.Cast<Animal>();

var joinQuery =
from animal in animalQuery
join keylessanimal in queryTypeQuery on animal.Name equals keylessanimal.Name
select new
{
animal,
keylessanimal
};

var result = joinQuery.ToList();

Assert.Single(result);
}

private string NormalizeDelimitersInRawString(string sql)
=> ((RelationalTestStore)Fixture.TestStore).NormalizeDelimitersInRawString(sql);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,23 @@ FROM [Animal] AS [a]
ORDER BY [a].[Name]");
}

public override void Casting_to_base_type_joining_with_query_type_works()
{
base.Casting_to_base_type_joining_with_query_type_works();

AssertSql(
@"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [t].[FoundOn]
FROM [Animal] AS [a]
INNER JOIN (
SELECT [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[Group], [a0].[FoundOn]
FROM (
Select * from ""Animal""
) AS [a0]
WHERE [a0].[Discriminator] IN (N'Eagle', N'Kiwi')
) AS [t] ON [a].[Name] = [t].[Name]
WHERE [a].[Discriminator] = N'Eagle'");
}

protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
=> facade.UseTransaction(transaction.GetDbTransaction());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,23 @@ FROM [Animal] AS [a]
ORDER BY [a].[Name]");
}

public override void Casting_to_base_type_joining_with_query_type_works()
{
base.Casting_to_base_type_joining_with_query_type_works();

AssertSql(
@"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [t].[FoundOn]
FROM [Animal] AS [a]
INNER JOIN (
SELECT [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[Group], [a0].[FoundOn]
FROM (
Select * from ""Animal""
) AS [a0]
WHERE [a0].[Discriminator] IN (N'Eagle', N'Kiwi')
) AS [t] ON [a].[Name] = [t].[Name]
WHERE [a].[Discriminator] = N'Eagle'");
}

protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
=> facade.UseTransaction(transaction.GetDbTransaction());

Expand Down

0 comments on commit 1d40504

Please sign in to comment.