【问题标题】:The name of dynamic property was already used as the declared property name of open type动态属性的名称已被用作开放类型的声明属性名称
【发布时间】:2018-08-24 16:44:38
【问题描述】:

我有一个看起来像这样的实体:

public class Item
{
    public int Id { get; set; }

    public IDictionary<string, object> Settings { get; set; }
}

OData 自动生成以下 JSON 输出,将 JSON 属性置于实体级别:

{
    "@odata.context":"http://localhost/odata/$metadata#Items",
    "value":[
        {
            "Id":1,
            "Setting1":"Value",
            "Setting2":10
        }
    ]
}

我不希望这样,因为我的 JSON 可能有一个同名的属性,这将导致错误:动态属性“Id”的名称已被用作开放类型的声明属性名称。

如何禁用 OData 对开放类型的自动映射?

【问题讨论】:

标签: c# odata


【解决方案1】:

解决方案是创建一个单独的实体。这将返回所需的结果。

public class Item
{
    public int Id { get; set; }

    public OpenType Settings { get; set; }
}

public class OpenType
{
    public IDictionary<string, object> Settings { get; set; }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-25
    • 2012-08-21
    • 1970-01-01
    • 2017-06-29
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多