实体框架核心PostgreSQL EF.Functions.JsonTypeof

时间:2020-05-25 15:39:04

标签: postgresql entity-framework-core npgsql

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

https://www.npgsql.org/efcore/mapping/json.html?tabs=data-annotations%2Cjsondocument中的此语法无效!显示此错误:无法将“字符串”隐式转换为“布尔”

1 个答案:

答案 0 :(得分:1)

链接的示例语法完全不完整。 JsonTypeof返回string,并根据链接映射到jsonb_typeof,其中

将最外面的JSON值的类型作为文本字符串返回。可能的类型是对象,数组,字符串,数字,布尔值和null。

例如,Where子句中正确的示例用法会将方法的返回值与包含上述值之一的字符串进行比较

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