1

.Where(e => EF.Functions.JsonTypeof(e.Customer.GetProperty("Age")))

This syntax in https://www.npgsql.org/efcore/mapping/json.html?tabs=data-annotations%2Cjsondocument not works!! show this error: cannot implicitly convert "string" to "bool"

1 Answer 1

1

The sample syntax from the link is simply incomplete. JsonTypeof returns string an according to the link is mapped to jsonb_typeof which

Returns the type of the outermost JSON value as a text string. Possible types are object, array, string, number, boolean, and null.

So the correct sample usage in Where clause would compare the return value of the method to a string containing one of the aforementioned values, for instance

.Where(e => EF.Functions.JsonTypeof(e.Customer.GetProperty("Age")) == "number")
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @ivan-stoev, I've pushed a fix to the doc sample.
@jrocha76 Then you simply need different function - EF.Functions.JsonExists, with sample usage from the link .Where(e => EF.Functions.JsonExists(e.Customer, "Age")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.