IsReference property in data contract

What is the purpose of the IsReference property in a DataContract ? How do request and response change when using this property?

+44
wcf datacontract
Jun 24 '09 at 8:57
source share
2 answers

Determines how objects are serialized by default, IsReference=false .

Setting IsReference = true allows you to serialize object trees that can refer to each other. So, with a list of Employees , each of which has a property for Manager (who is also an Employee ), a reference to Manager for each Employee can be stored rather than embed a Manager inside each Employee node:

IsReference=false will create:

 <Employee> <Manager i:nil="true" /> <Name>Kenny</Name> </Employee> <Employee> <Manager> <Manager i:nil="true" /> <Name>Kenny</Name> </Manager> <Name>Bob</Name> </Employee> <Employee> <Manager> <Manager i:nil="true" /> <Name>Kenny</Name> </Manager> <Name>Alice</Name> </Employee> 

Where as IsReference=true will be produced:

 <Employee z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <Manager i:nil="true" /> <Name>Kenny</Name> </Employee> <Employee z:Id="i2" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <Manager z:Ref="i1" /> <Name>Bob</Name> </Employee> <Employee z:Id="i3" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <Manager z:Ref="i1" /> <Name>Alice</Name> </Employee> 

Fragments taken from this weblog , which has a full explanation along with examples of generated XML with the property applied.

The MSDN - IsReference Property contains detailed information as well as Interactive Object References .

+56
Jun 24 '09 at 12:05
source share

Also IsReference does not exist in the .NET Framework 3.5. Thus, you may get errors when using this version of the Framework - it exists only in versions 4.5, 4, 3.5 SP1 and Silverlight.

"Error 297 'System.Runtime.Serialization.DataContractAttribute' does not contain a definition for 'IsReference'"

+2
Apr 22 '10 at 10:21
source share



All Articles