-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix to #20609 - Includes() with string throws not finding navigation path exception when type T is derived #20630
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using JetBrains.Annotations; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Diagnostics | ||
{ | ||
/// <summary> | ||
/// A <see cref="DiagnosticSource" /> event payload class for events that have | ||
/// invalid include path information. | ||
/// </summary> | ||
public class InvalidIncludePathEventData : EventData | ||
{ | ||
/// <summary> | ||
/// Constructs the event payload. | ||
/// </summary> | ||
/// <param name="eventDefinition"> The event definition. </param> | ||
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param> | ||
/// <param name="navigationChain"> Navigation chain included to this point. </param> | ||
/// <param name="navigationName"> The name of the invalid navigation. </param> | ||
public InvalidIncludePathEventData( | ||
[NotNull] EventDefinitionBase eventDefinition, | ||
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator, | ||
[NotNull] string navigationChain, | ||
[NotNull] string navigationName) | ||
: base(eventDefinition, messageGenerator) | ||
{ | ||
NavigationChain = navigationChain; | ||
NavigationName = navigationName; | ||
} | ||
|
||
/// <summary> | ||
/// Navigation chain included to this point. | ||
/// </summary> | ||
public virtual string NavigationChain { get; } | ||
|
||
/// <summary> | ||
/// The name of the invalid navigation. | ||
/// </summary> | ||
public virtual string NavigationName { get; } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7207,6 +7207,75 @@ private class MyModel20097 : IHaveId20097 | |
|
||
#endregion | ||
|
||
#region Issue20609 | ||
|
||
[ConditionalFact] | ||
public virtual void Can_ignore_invalid_include_path_error() | ||
{ | ||
using var context = CreateContext20609(); | ||
var result = context.Set<ClassA>().Include("SubB").ToList(); | ||
} | ||
|
||
public class BaseClass | ||
{ | ||
public string Id { get; set; } | ||
} | ||
|
||
public class ClassA : BaseClass | ||
{ | ||
public SubA SubA { get; set; } | ||
} | ||
|
||
public class ClassB : BaseClass | ||
{ | ||
public SubB SubB { get; set; } | ||
} | ||
|
||
public class SubA | ||
{ | ||
public int Id { get; set; } | ||
} | ||
|
||
public class SubB | ||
{ | ||
public int Id { get; set; } | ||
} | ||
|
||
private BugContext20609 CreateContext20609() | ||
{ | ||
var testStore = SqlServerTestStore.CreateInitialized("QueryBugsTest", multipleActiveResultSets: true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the right way to do custom warnings config in qbt? @AndriySvyryd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, but it's fine for now. Tracked by #17588 |
||
var options = Fixture.AddOptions(testStore.AddProviderOptions(new DbContextOptionsBuilder())) | ||
.EnableDetailedErrors() | ||
.EnableServiceProviderCaching(false) | ||
.ConfigureWarnings(x => x.Ignore(CoreEventId.InvalidIncludePathError)) | ||
.Options; | ||
|
||
var context = new BugContext20609(options); | ||
context.Database.EnsureCreatedResiliently(); | ||
|
||
return context; | ||
} | ||
|
||
private class BugContext20609 : DbContext | ||
{ | ||
public BugContext20609(DbContextOptions options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<BaseClass> BaseClasses { get; set; } | ||
public DbSet<SubA> SubAs { get; set; } | ||
public DbSet<SubB> SubBs { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<ClassA>().HasBaseType<BaseClass>().HasOne(x => x.SubA).WithMany(); | ||
modelBuilder.Entity<ClassB>().HasBaseType<BaseClass>().HasOne(x => x.SubB).WithMany(); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
private DbContextOptions _options; | ||
|
||
private SqlServerTestStore CreateTestStore<TContext>( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"couldn't" -> "could not"?