简体   繁体   English

ModelMetadataType 对 asp.net core 2.0 中的模型没有影响

[英]ModelMetadataType has no effect on model in asp.net core 2.0

[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; }
}

Here is example of sample code.这是示例代码的示例。

ModelMetadataType has no effect (DatabaseGenerated data annotation doesn't added to the appropriate properties). ModelMetadataType 无效(DatabaseGenerated 数据注释未添加到适当的属性)。 Am I doing something wrong?难道我做错了什么?

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; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM