ASP.NET Web API:JsonIgnore属性仅用于set或get

时间:2019-07-13 20:36:59

标签: asp.net json entity-framework asp.net-web-api annotations

使用实体框架表类。

我需要排除一些属性,因此我正在使用[JsonIgnore],当我想同时排除set和get时,这是完全可以的。

public class NamTable
{
    [JsonIgnore]
    public long id { get; set; }
    public string name { get; set; }
    public string mail { get; set; }
    public string mobile { get; set; }
    [JsonIgnore]
    public System.DateTime timestamp { get; set; }
}

但是我只需要为set或get排除一些属性。

示例是idtimestamp,它们在插入或设置过程中是不需要的,但是在执行get请求时我需要它们。那么我需要添加哪个注释来实现这一目标?

我知道下面是错误的,但是看起来是类似的方法...

public class NamTable
{
    public long id { get; [JsonIgnore] set; }
    public string name { get; set; }
    public string mail { get; set; }
    public string mobile { get; set; }

    public System.DateTime timestamp { get; [JsonIgnore] set; }
}

0 个答案:

没有答案