Description:
Been working on getting ready for .NET 10, but noticed that the 10.0.0-rc package seems to have issues when using .Where in Linq with .Contains call in predicate.
How to repeat:
1. Create an empty API project/
2. Add a BugDbContext that has a DbSet<FakeEntity> property. A fake entity should have an ID property and a name property. Register this DB context in the DI container.
4. Add a BugRepository class that consumes the BugDbContext from the DI container, and also has a public method called trigger that has the following implementation. And register it in the DI container as a scoped service.
"
public async Task Trigger()
{
await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity One" });
await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Two" });
await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Three" });
await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Four" });
await dbContext.SaveChangesAsync();
string[] list = ["Fake Entity One", "Fake Entity Four"];
var result = await dbContext.FakeEntities.Where(x => list.Contains(x.Name))
.ToListAsync();
Console.WriteLine("Result of Query {Count} found", result.Count);
}
"
5. After builder.Build a class that gets the BugRepository from the DI container and calls the method trigger. You can do this like this.
"
var service = app.Services.GetRequiredService<BugRepository>();
await service.Trigger();
"
6. now if you run this web application you should see an error like this.
"Unhandled exception. System.InvalidOperationException: Expression '@list' in the SQL tree does not have a type mapping assigned."
Description: Been working on getting ready for .NET 10, but noticed that the 10.0.0-rc package seems to have issues when using .Where in Linq with .Contains call in predicate. How to repeat: 1. Create an empty API project/ 2. Add a BugDbContext that has a DbSet<FakeEntity> property. A fake entity should have an ID property and a name property. Register this DB context in the DI container. 4. Add a BugRepository class that consumes the BugDbContext from the DI container, and also has a public method called trigger that has the following implementation. And register it in the DI container as a scoped service. " public async Task Trigger() { await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity One" }); await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Two" }); await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Three" }); await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Four" }); await dbContext.SaveChangesAsync(); string[] list = ["Fake Entity One", "Fake Entity Four"]; var result = await dbContext.FakeEntities.Where(x => list.Contains(x.Name)) .ToListAsync(); Console.WriteLine("Result of Query {Count} found", result.Count); } " 5. After builder.Build a class that gets the BugRepository from the DI container and calls the method trigger. You can do this like this. " var service = app.Services.GetRequiredService<BugRepository>(); await service.Trigger(); " 6. now if you run this web application you should see an error like this. "Unhandled exception. System.InvalidOperationException: Expression '@list' in the SQL tree does not have a type mapping assigned."