Skip to content
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

Select or filter Length of string contained in JsonB column #3229

Open
slava-se opened this issue Jul 22, 2024 · 0 comments
Open

Select or filter Length of string contained in JsonB column #3229

slava-se opened this issue Jul 22, 2024 · 0 comments

Comments

@slava-se
Copy link

EF Core 8.0.7

I have a table MyEvent which contains a JsonB "Description" column which is an object containing 2 strings:

    public class MyEvent
    {
        [Key]
        public int Id { get; set; }

        [Column(TypeName = "jsonb")]
        public Translations Description { get; set; } = null!;
     }
public class Translations
{
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
    public string? En { get; set; }

    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
    public string? De { get; set; }
}

Data is definitely there as I can select it and it's Length is 756.

            var result = await _dbContext.MyEvents
                .Where(e =>e.Id == eventId)
                .Select(e => e.Description.En)
                .SingleAsync();

But if I'm trying to select the Length then it throws the System.InvalidOperationException: 'Nullable object must have a value.'

            var result = await _dbContext.MyEvents
                .Where(e =>e.Id == eventId)
                .Select(e => e.Description.En.Length)
                .SingleAsync();

Trying to use it as a where filter returns false even though it should be true.

            var result = await _dbContext.MyEvents
                .Where(e =>e.Id == eventId && e.Description.En.Length)
                .SingleAsync();

Is Length not yet supported and I have to load the data to evaluate it's length?
I've checked the docs and couldn't find anything useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant