EF Core 7 Json 数组的列映射

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

我有一个带有 json 列“Extras”的 sql 表

  [{"Key":"Part Number","Value":123},{"Key":"Batch Number","Value":321},{"Key":"Quantity","Value":"3"}]

我正在尝试将其映射到我的班 LinerReceiptLog。我添加了一个名为 tag 的新类,它具有 Key 和 Value 属性

public partial class LinerReceiptLog
{
    public long LinerReceiptLogId { get; set; }

    public int EmployeeId { get; set; }

    public DateTime LogDate { get; set; }

    public int TotalQty { get; set; }

    public string Ncrnumber { get; set; }

    public List<Tag> Extras { get; set; }

    public virtual Employee Employee { get; set; }
}

public class Tag
{
    public string Key { get; set; }
    public string Value { get; set; }
}

我更新了模型构建器

entity.OwnsMany(e => e.Extras, builder=>builder.ToJson());

当我运行代码来查询数据库上下文时 我得到这个异常。

System.InvalidOperationException: 'The requested operation requires an element of type 'Array', but the target element has type 'Object'.'

我一直在关注这篇文章 https://blog.jetbrains.com/dotnet/2023/02/14/getting-started-entity-framework-core-7-json-support/

c# entity-framework entity-framework-core
1个回答
0
投票

从那以后你有解决方案吗?

© www.soinside.com 2019 - 2024. All rights reserved.