2 Mayıs 2014

Inheriting and using DataContract classes at WCF

If you have classes inherit from one to another, serialization framework can not know what entity is what type so you must declare this kind of relation by an attribute which is KnownType.

Here is an exampe:
[DataContract]
[KnownType(typeof(B))]
public class A
{
   [DataMember]
   public string Value { get; set; }
}

[DataContract]
public class B : A
{
   [DataMember]
   public string OtherValue { get; set; }
}
Source