在实体框架(首先是数据库)中,我试图向创建的类添加一些数据注释。
一般来说:我创建了 X 类:
namespace Info
{
using System;
using System.Collections.Generic;
public partial class X
{
public string SomeProperty {get; set;}
...
}
}
我希望SomeProperty
在序列化为 JSON 时忽略属性,因此在App_Code/Metadata
我创建类 X.cs 并添加一些元数据:
namespace Info
{
public class XMetaData
{
[JsonIgnore]
public string SomeProperty{get; set;}
}
[MetadataType(typeof(XMetaData))]
public partial class X
{
}
}
上面我已经手动将命名空间从更改Info.App_Code.Metadata
为Info
匹配部分类。
但是,在我使用 X 类的所有地方,我都有警告
The type Info.X in '.../Info/App_Code/Metadata/X.cs ' conflicts with the imported type Info.X in '.../Info/X.cs'. Using the type defined in '.../Info/App_Code/Metadata/X.cs '
我预计这两个部分类将被合并,但是所有出现都指的是那个空的一个 X 类。
有人知道我错过了什么吗?