-
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
Filtering by Contains with HierarchyId and AsSplitQuery is not working #32976
Labels
area-query
area-sqlserver
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Comments
Confirmed bug in main. The scenario above itself isn't a regression since hierarchyid support was introduced in 8.0, but the underlying issue is any transformation from OPENJSON with WITH to without WITH; this affects other scenarios as well (i.e. when the OPENJSON collection order needs to be preserved). Simplified reproawait using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
ctx.Blogs.Add(new Blog());
await ctx.SaveChangesAsync();
HierarchyId[] nodeIdFilter = [HierarchyId.GetRoot()];
_ = await ctx
.Blogs
.Include(b => b.Posts)
.Where(b => nodeIdFilter.Contains(b.NodeId))
.AsSplitQuery()
.ToListAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(
"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false",
o => o.UseHierarchyId())
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Blog
{
public int Id { get; set; }
public List<Post> Posts { get; set; }
public HierarchyId NodeId { get; set; } = HierarchyId.GetRoot();
}
public class Post
{
public int Id { get; set; }
public required Blog Blog { get; set; }
} |
roji
added a commit
to roji/efcore
that referenced
this issue
Jan 31, 2024
roji
added
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
Servicing-consider
labels
Jan 31, 2024
roji
added a commit
that referenced
this issue
Feb 1, 2024
roji
added a commit
to roji/efcore
that referenced
this issue
Feb 7, 2024
Fixes dotnet#32976 (cherry picked from commit 451514e)
roji
added a commit
to roji/efcore
that referenced
this issue
Feb 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-query
area-sqlserver
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
File a bug
Using a contains filter with HierarchyId in a spilt query scenario is throwing following exception:
Microsoft.Data.SqlClient.SqlException (0x80131904): CLR types cannot be used as column types in OPENJSON function with explicit schema. CLR types are not supported in WITH clause.
I found this related issue: #31930
Include your code
You can find a full working repro here: https://github.com/IT-CASADO/EfCoreBugs
Please run the unit test: SplitQueryWithHierarchyIdFilter
Include stack traces
Include provider and version information
EF Core version: 8.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows
IDE: Visual Studio 2022 17.8.5
The text was updated successfully, but these errors were encountered: