【问题标题】:Entity Framework Core PostgreSQL EF.Functions.JsonTypeof实体框架核心 PostgreSQL EF.Functions.JsonTypeof
【发布时间】:2020-09-12 07:06:36
【问题描述】:

.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】:

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

    以文本字符串的形式返回最外层 JSON 值的类型。可能的类型有对象、数组、字符串、数字、布尔值和空值。

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

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

    【讨论】:

    • 感谢@ivan-stoev,我已经对文档示例进行了修复。
    • @jrocha76 然后你只需要不同的功能 - EF.Functions.JsonExists,来自链接.Where(e => EF.Functions.JsonExists(e.Customer, "Age")的示例用法
    猜你喜欢
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2020-05-10
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多