Daniel Robinson
Daniel Robinson

Reputation: 14858

c# wcf inherited [DataContract]

if I define a my types like this:

public class UniqueNamedItem
{
    int Id {public get; protected set;}
    int Name {public get; protected set;}
}

[DataContract]
public class Product : UniqueNamedItem
{
    [DataMember]
    //lots of properties and members etc
}

Do I need to add the [DataContract] and [DataMember] attributes to the base class in order to use those properties and members in communications? or is this added automatically because the derived type is a DataContract?

Upvotes: 1

Views: 99

Answers (1)

user1527329
user1527329

Reputation: 529

You need to add it. Also please note, if you want to return the base class directly, you need to add the KnownTypeAttribute to your base class which points to your subclass.

Upvotes: 2

Related Questions