[英]EF code first: inheriting from common base class, WEB api losing base properties
I would like to use the following as a base class for all my classes: 我想将以下内容用作所有类的基类:
[DataContract(IsReference = true)]
public abstract class EsBase
{
[DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
public Guid ID { get; set; }
public bool SoftDelete { get; set; }
}
With example child class: 带有示例子类:
public class Match : EsBase
{
[Display(Name = "Start time")]
public DateTime StartTime { get; set; }
}
Problem is that when Match object is sent out through WEB API I do not have access to ID or SoftDelete. 问题是,当通过WEB API发送Match对象时,我无权访问ID或SoftDelete。
How to pass these as well into output? 如何将这些也传递到输出中?
Just add [DataMember]
attribute to the properties of your DataContract class. 只需将
[DataMember]
属性添加到DataContract类的属性即可。 This then makes those properties become part of the serialization of your DataContract object. 然后,这会使这些属性成为DataContract对象序列化的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.