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

EF.Functions support for json_array_length #3154

Open
alastair-todd opened this issue Apr 15, 2024 · 2 comments
Open

EF.Functions support for json_array_length #3154

alastair-todd opened this issue Apr 15, 2024 · 2 comments

Comments

@alastair-todd
Copy link

alastair-todd commented Apr 15, 2024

I could be mistaken but EF.Functions support for JSON appears limited.

I have a dynamic JSON column (no fixed POCO) which is storing an array of objects. Sometimes this is stored as an empty array, and I want to filter out those rows.

This is the working SQL, but I don't seem to be able to attain this using EF.Functions.

SELECT "Id", "Json"
	FROM "Reporting"."ReportSnapshot"
	where jsonb_array_length("Json") > 0;
@roji
Copy link
Member

roji commented Apr 15, 2024

Have you tried using GetArrayLength() as per the docs?

customer.RootElement.GetProperty("Orders").GetArrayLength()

@alastair-todd
Copy link
Author

I didn't think it was relevant to my use case as I've gone for "string mapping" over JsonDocument.

I will try it out.

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

2 participants