这个问题是因为在使用Entity Framework Core Code First时,忽略基类属性在序列化时仍然会被包含在结果中。解决方法如下:
public class BaseEntity
{
[NotMapped]
public int IgnoredProperty { get; set; }
}
public class DerivedEntity : BaseEntity
{
[JsonIgnore]
public int IgnoredProperty { get; set; }
}
这样,在序列化派生类的实例时,忽略的属性就不会被序列化了。