Skip to content
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 @@ -92,7 +92,8 @@ public virtual void ProcessModelFinalizing(
ProxiesStrings.NonVirtualProperty(navigationBase.Name, entityType.DisplayName()));
}

if (_options.UseLazyLoadingProxies)
if (_options.UseLazyLoadingProxies
&& navigationBase.LazyLoadingEnabled)
{
if (!navigationBase.PropertyInfo.GetMethod!.IsReallyVirtual())
{
Expand Down
23 changes: 23 additions & 0 deletions test/EFCore.Proxies.Tests/LazyLoadingProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public void Does_not_throw_if_non_virtual_navigation_to_non_owned_type_is_allowe
context.Model.FindEntityType(typeof(LazyNonVirtualNavEntity))!.FindNavigation(nameof(LazyNonVirtualNavEntity.SelfRef)));
}

[ConditionalFact]
public void Does_not_throw_if_non_virtual_navigation_is_set_to_not_eager_load()
{
using var context = new LazyContextDisabledNavigation();
Assert.NotNull(
context.Model.FindEntityType(typeof(LazyNonVirtualNavEntity))!.FindNavigation(nameof(LazyNonVirtualNavEntity.SelfRef)));
}

[ConditionalFact]
public void Does_not_throw_if_non_virtual_navigation_to_owned_type()
{
Expand Down Expand Up @@ -108,6 +116,21 @@ public LazyContext()
}
}

private class LazyContextDisabledNavigation : TestContext<LazyNonVirtualNavEntity>
{
public LazyContextDisabledNavigation()
: base(dbName: "LazyLoadingContext", useLazyLoading: true, useChangeDetection: false)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<LazyNonVirtualNavEntity>().Navigation(e => e.SelfRef).EnableLazyLoading(false);
}
}

public sealed class LazySealedEntity
{
public int Id { get; set; }
Expand Down