Exitos
Exitos

Reputation: 29720

What is the difference between [DataContractAttribute(IsReference=true)] and [DataContract]

I'm trying to write a WCF Web service that will return my data as JSON so I can call it from some client script.

I know I need to decorate any classes I want to return from the Web Methods in a [DataContract] attribute and then any Members in a [DataMember]. That in mind I want to return entity types so I went to the Entity ObjectContext classes.

However when I look at the .edmx file I can see that the classes have been decorated like so...

[EdmEntityTypeAttribute(NamespaceName="PteDotNetModel", Name="AssocFile")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class AssocFile : EntityObject

When I then try and add [DataContract] I get an error saying I can't have duplicated attributes. I'm confused whilst they are similar they are clearly different no?

The second part of my question is how I return entity types over a WCF service?

Upvotes: 0

Views: 2362

Answers (1)

Michael Petrotta
Michael Petrotta

Reputation: 60942

The two attributes are the same; the trailing "Attribute" can be excluded. From MSDN:

By convention, all attribute names end with the word "Attribute" to distinguish them from other items in the .NET Framework. However, you do not need to specify the attribute suffix when using attributes in code.

Upvotes: 4

Related Questions