MapsterMapper / MapsterMapper/Mapster.EFCore

ProjectToType with NpgSql JSONB data type

Open
#1 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
8
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Query fails with exception when used ProjectToType with entity having child class in JSONB format (EF.Core 7):

"The LINQ expression 'namelessParameter{0} => new Dto{ Number = namelessParameter{0}.Number, Date = namelessParameter{0}.Date, Amount = namelessParameter{0}.Amount' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.

EF.Core without using ProjectToType translates it corerctly.

`
public class Entity
{
public string Id { get; set; }
public string Name { get; set; }
public Info[] Info
}

public class Info
{
public string Number { get; set; }
public DateOnly Date { get; set; }
public decimal Amount { get; set; }
}

public class EntityConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(u => u.Id);
builder.Property(p => p.Info)
.HasColumnType("jsonb");
}
}
`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the EF Core 7 query that uses ProjectToType with an entity whose Info array is stored as PostgreSQL JSONB, then compare it with the working query that does not use ProjectToType. No source file or test is named; done means the ProjectToType query translates successfully without requiring client evaluation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, postgresql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.