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

Regression test for TPH model with lazy loading #19409

Merged
merged 1 commit into from
Dec 30, 2019
Merged
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
36 changes: 36 additions & 0 deletions test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,18 @@ public virtual void Lazy_loading_shares_service__property_on_derived_types()
entity.BaseNoses.Select(b => b.Size).OrderBy(h => h));
}

[ConditionalFact]
public virtual void Lazy_loading_handles_shadow_nullable_GUID_FK_in_TPH_model()
{
using var context = CreateContext(lazyLoadingEnabled: true);

var tribes = context.Set<Tribe>().ToList();

Assert.Single(tribes);
Assert.IsAssignableFrom<Quest>(tribes[0]);
Assert.Equal(new DateTime(1973, 9, 3), ((Quest)tribes[0]).Birthday);
}

[ConditionalFact]
public virtual void Lazy_loading_finds_correct_entity_type_with_alternate_model()
{
Expand Down Expand Up @@ -2314,6 +2326,8 @@ public class Company : Entity

public class Parson : Entity
{
public DateTime Birthday { set; get; }

public virtual ICollection<Nose> ParsonNoses { get; set; }
}

Expand All @@ -2322,6 +2336,22 @@ public class Host
public string HostName { get; set; }
}

public abstract class Tribe
{
public Guid Id { get; set; }
}

public class Called : Tribe
{
public string Name { set; get; }
}

public class Quest : Tribe
{
public DateTime Birthday { set; get; }
public virtual Called Called { set; get; }
}

protected DbContext CreateContext(bool lazyLoadingEnabled = false)
{
var context = Fixture.CreateContext();
Expand Down Expand Up @@ -2375,6 +2405,10 @@ protected override IServiceCollection AddServices(IServiceCollection serviceColl

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
modelBuilder.Entity<Tribe>();
modelBuilder.Entity<Called>();
modelBuilder.Entity<Quest>();

modelBuilder.Entity<Entity>();
modelBuilder.Entity<Company>();
modelBuilder.Entity<Parson>();
Expand Down Expand Up @@ -2516,6 +2550,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con

protected override void Seed(DbContext context)
{
context.Add(new Quest { Birthday = new DateTime(1973, 9, 3) });

context.Add(
new Parent
{
Expand Down