【问题标题】:ModelMetadataType has no effect on model in asp.net core 2.0ModelMetadataType 对 asp.net core 2.0 中的模型没有影响
【发布时间】:2017-10-07 23:12:57
【问题描述】:
[ModelMetadataType(typeof(ITemporalData))]
public partial class Person : ITemporalData
{

}


public partial class Person
{
        public DateTime SysStartDate { get; set; }
        public DateTime SysEndDate { get; set; }
}

public interface ITemporalData
{
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        DateTime SysStartDate { get; set; }

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        DateTime SysEndDate { get; set; }
}

这里是示例代码示例。

ModelMetadataType 无效(DatabaseGenerated 数据注释未添加到适当的属性)。难道我做错了什么?

【问题讨论】:

标签: c# .net asp.net-core asp.net-core-2.0 metadatatype


【解决方案1】:
Asp.Net Core Web Api


using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;


[ModelMetadataType(typeof(IPerson))]
public partial class Person : IPerson
{

}

public partial class Person
{
    public string Name { get; set; }
    public string Surname { get; set; }
}

public interface IPerson
{
    [JsonIgnore]
    string Name { get; set; }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 2019-04-24
    • 2014-04-18
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    相关资源
    最近更新 更多