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
Expression in the SQL tree does not have a type mapping assigned #33582
Comments
Converting the
I am not sure, it seems that EF Core -at the moment- isn't able to figure out the type of the |
I can't reproduce the problem on my end. I'm using the following code: using var ctx = new MyContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
await ctx.Set<Entity>().AddAsync(new Entity { Value = 0 });
await ctx.Set<Entity>().AddAsync(new Entity { Value = 1 });
await ctx.SaveChangesAsync();
string[] values = new[] { "one", "two", "three", "four" };
var query = (from item in ctx.Set<Entity>()
let value = values[item.Value]
select new { item.Id, value }).ToList();
Console.WriteLine(query);
public class Entity
{
public int Id { get; set; }
public int Value { get; set; }
}
public class MyContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Repro;Trusted_Connection=True;MultipleActiveResultSets=true");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Entity>();
}
} I get expected results and the sql is as follows: exec sp_executesql N'SELECT [e].[Id], JSON_VALUE(@__values_0, ''$['' + CAST([e].[Value] AS nvarchar(max)) + '']'') AS [value]
FROM [Entity] AS [e]',N'@__values_0 nvarchar(4000)',@__values_0=N'["one","two","three","four"]' @edamascus can you modify the code I pasted above, so that it reproduces the problem you are seeing? Also, are you using the latest patch of EF 8? |
@maumar, the current version of EF Core I am using is |
@maumar, I had to simplify the actual code which I am having trouble with in order to report the issue. When declaring the
|
@edamascus there have been many fixes that could be related to this, please try with the latest patch version. In fact, that's a good idea to always do before filing an issue. |
@roji, my fault for missing out the important part which caused the issue. The problem exists in versions
The following query (with string conversion) works:
|
Not sure if this is related. But the same code fails with the following exception when
In order to fix the issue, I have to re-evaluate
|
I'm able to reproduce this on current bits. Problem is that SqlExpressionFactory.Case applies TypeMapping for elseResult based on type mappings before we run type inference code - we use provided type mapping and the type mappings from When clauses, but they are all null. |
The following query was working fine in EF Core 7:
However, after upgrading to EF Core 8, the following exception is thrown:
I checked the breaking changes documentation and I am running SQL Server 2022 with compatibility level set for my database to
160
.What am I missing here?
The text was updated successfully, but these errors were encountered: