EF代码优先:继承公共基类,WEB api丢失基本属性

时间:2015-09-07 03:29:17

标签: c# entity-framework asp.net-web-api asp.net-web-api2

我想将以下内容用作我所有类的基类:

[DataContract(IsReference = true)]
public abstract class EsBase
{
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public Guid ID { get; set; }

    public bool SoftDelete { get; set; }
}

使用示例子类:

public class Match : EsBase
{                
    [Display(Name = "Start time")]
    public DateTime StartTime { get; set; }
}

问题是,当通过WEB API发送Match对象时,我无法访问ID或SoftDelete。

如何将这些传递给输出?

1 个答案:

答案 0 :(得分:1)

只需将[DataMember]属性添加到DataContract类的属性即可。然后,这些属性将成为DataContract对象序列化的一部分。

相关问题