-
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
"Index was out of range" in ShaperProcessingExpressionVisitor.JsonEntityMaterializerRewriter #32431
Comments
problem here is that Headers is |
I ran into this same issue today. If you do not require filtering by the JSON property, then you can use this as a work-around. |
I get this error not only to Dictionary mapping. |
@totpero in that case we need to see a code sample. |
I got the same error without any dictionaries while trying to create repro for another issue... Codeusing Microsoft.EntityFrameworkCore;
await using var context = new TestContext();
var thisFails = context.MainModels.ToList();
public sealed class TestContext : DbContext
{
private const string ConnectionString = "";
public DbSet<MainModel> MainModels { get; set; }
public TestContext()
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseNpgsql(ConnectionString);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MainModel>()
.OwnsOne(x => x.JsonModel, builder =>
{
builder.ToJson();
builder.OwnsMany(d => d.InnerModels);
});
}
}
public class MainModel
{
public int Id { get; set; }
public JsonModel JsonModel { get; set; }
}
public class JsonModel
{
public List<JsonInnerModel> InnerModels { get; set; }
}
public class JsonInnerModel
{
public int Id { get; set; }
} Stack trace
UPD: if I change my query to var thisFails = context.MainModels
.Where(mainModel => mainModel.JsonModel.InnerModels.Any(inner => inner.Id == 1))
.ToList(); I'm getting yet another strange exception: Stack trace 2
|
Thanks for the insight @maumar! [Table("email_report")]
public class EmailReport
{
public int EmailReportId { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Instant Created { get; set; }
public List<EmailReportParagraphBase> Paragraphs { get; set; } = [];
}
// This should probably be abstract. EF Core requires either an instantiable type or derived classes as part of the model though (didn't test the latter but the exception thrown says so).
[JsonDerivedType(typeof(MarkdownParagraph), typeDiscriminator: "markdown")]
[JsonDerivedType(typeof(TableFromSqlParagraph), typeDiscriminator: "tableFromSql")]
public class EmailReportParagraphBase
{
}
public sealed class MarkdownParagraph : EmailReportParagraphBase
{
public required string Markdown { get; set; }
}
public sealed class TableFromSqlParagraph : EmailReportParagraphBase
{
public required string Query { get; set; }
}
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{
}
public DbSet<EmailReport> EmailReports { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EmailReport>(er =>
{
er.Property(x => x.Created).HasDefaultValueSql("now()");
});
modelBuilder.Entity<EmailReport>().OwnsMany(e => e.Paragraphs, p => p.ToJson());
}
}
Mostly duplicate of #27779 |
I am getting the same error with version 8.0.4. I am using Jsonb but not using dictionaries. |
Seems to be the same issue in version 8.0.6. |
I've re-tested the code the samples provided and things work fine on my end. @KeterSCP 's issue with var thisFails = context.MainModels is caused by the fact that |
@dks07 @PatrikFomin the issue throws a generic exception so it's possible this is a different bug. Can you please file new issue and provide the repro code? |
fixed by #32966 |
With the repro below, the following exception is thrown:
Repro
Originally opened by @maxwidergy for PostgreSQL in npgsql/efcore.pg#2988
The text was updated successfully, but these errors were encountered: