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

Throw when attempting to lazy-load after no-tracking query #10851

Merged
merged 1 commit into from
Feb 5, 2018
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
42 changes: 42 additions & 0 deletions src/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,48 @@ public virtual void Lazy_load_reference_to_dependent_for_detached_is_no_op()
Assert.Null(parent.Single);
}
}

[Fact]
public virtual void Lazy_load_collection_for_no_tracking_throws()
{
using (var context = CreateContext(lazyLoadingEnabled: true))
{
var parent = context.Set<Parent>().AsNoTracking().Single();

Assert.Equal(
CoreStrings.CannotLoadDetached(nameof(Parent.Children), nameof(Parent)),
Assert.Throws<InvalidOperationException>(
() => parent.Children).Message);
}
}

[Fact]
public virtual void Lazy_load_reference_to_principal_for_no_tracking_throws()
{
using (var context = CreateContext(lazyLoadingEnabled: true))
{
var child = context.Set<Child>().AsNoTracking().Single(e => e.Id == 12);

Assert.Equal(
CoreStrings.CannotLoadDetached(nameof(Child.Parent), nameof(Child)),
Assert.Throws<InvalidOperationException>(
() => child.Parent).Message);
}
}

[Fact]
public virtual void Lazy_load_reference_to_dependent_for_no_tracking_throws()
{
using (var context = CreateContext(lazyLoadingEnabled: true))
{
var parent = context.Set<Parent>().AsNoTracking().Single();

Assert.Equal(
CoreStrings.CannotLoadDetached(nameof(Parent.Single), nameof(Parent)),
Assert.Throws<InvalidOperationException>(
() => parent.Single).Message);
}
}

[Theory]
[InlineData(EntityState.Unchanged, true)]
Expand Down
Loading