[Entity Framework Core PostgreSQL EF.Functions.JsonTypeof

问题描述 投票:1回答:1

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

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

postgresql entity-framework-core npgsql
1个回答
1
投票

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

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

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

.Where(e => EF.Functions.JsonTypeof(e.Customer.GetProperty("Age")) == "number")
    
© www.soinside.com 2019 - 2024. All rights reserved.