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

Add test for runtime model generation with proxies #28621

Merged
merged 1 commit into from
Aug 9, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,47 @@ public class LazyPropertyEntity
public LazyConstructorEntity LazyConstructorEntity { get; set; }
}

[ConditionalFact]
public void Lazy_loading_proxies()
=> Test(
new LazyLoadingProxiesContext(),
new CompiledModelCodeGenerationOptions(),
assertModel: model =>
{
Assert.Equal(
typeof(ILazyLoader), model.FindEntityType(typeof(LazyProxiesEntity1))!.GetServiceProperties().Single().ClrType);
Assert.Equal(
typeof(ILazyLoader), model.FindEntityType(typeof(LazyProxiesEntity1))!.GetServiceProperties().Single().ClrType);
});

public class LazyLoadingProxiesContext : ContextBase
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<LazyProxiesEntity1>();
}

protected override void OnConfiguring(DbContextOptionsBuilder options)
=> base.OnConfiguring(options.UseLazyLoadingProxies());
}

public class LazyProxiesEntity1
{
public int Id { get; set; }

public virtual LazyProxiesEntity2 ReferenceNavigation { get; set; }
}

public class LazyProxiesEntity2
{
public ILazyLoader Loader { get; set; }

public int Id { get; set; }
public virtual ICollection<LazyProxiesEntity1> CollectionNavigation { get; set; }
}

[ConditionalFact]
public void Throws_for_query_filter()
=> Test(
Expand Down Expand Up @@ -4776,6 +4817,7 @@ protected void Test(
BuildReference.ByName("Microsoft.EntityFrameworkCore.Abstractions"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Cosmos"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.InMemory"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Proxies"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Sqlite"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite"),
Expand Down