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

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

[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 无效(DatabaseGenelated 数据注释未添加到相应的属性中)。难道我做错了什么?

最佳答案

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

关于c# - ModelMetadataType对asp.net core 2.0中的模型没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46625995/

相关文章:

c# - 如何使用自定义对象列表序列化一个类?

c# - .NET 应用程序最稳定的时间戳源是什么?

c# - 查找在上下文菜单下单击的节点

c# - 在 "01234567890"中格式化 "012.345.678-90"的更好方法?

c# - 协调 3 个列表的最佳算法

asp.net-core - Serilog - 如何停止请求生命周期日志并仅启用自定义信息日志

Java 泛型类类型的 C# 等效语法

.net - 惰性 ="false"对 NHibernate 映射的类元素有什么影响?

c# - 如何在启动时启动服务 (`IServiceCollection` )

dependency-injection - 通过依赖注入(inject)实现后台任务的 DbContext