This is a migrated thread and some comments may be shown as answers.

Do we need proxy objects still, or can I decorate my class?

1 Answer 53 Views
Web Services
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 09 May 2016, 07:12 PM
Do we still need to convert an OA object to a proxy, or can I decrotate the properties with an attribute to just cherrypick the serialized fields to JSON?

1 Answer, 1 is accepted

Sort by
0
Simeon Simeonov
Telerik team
answered on 12 May 2016, 08:12 PM
Hello Steve,

You can decorate the entity class and serialize it directly but this is not advisable. This can cause problems especially with navigation properties. In general we always advice to use dedicated DTO objects that define explicitly the contract object that will be serialized.

If you decide to serialize the entity object directly I would advice to create a detach copy of the object and serialize this new object. The reason is that in Telerik Data Access - navigation properties are lazy loaded. This means that out of the box when the serializer calls a navigation (reference or collection) property it will be loaded from the database and then serialized. The result is that if you ask for a single object you may load substantial portion of your data if there are navigation properties in the target entity type. To overcome this behavior I suggest that you use CreateDetachedCopy method to disable lazy loading during serialization and control what portions of your object graph is sent to the client.

Also for an example please check
Dimitar Tachev answer here.

Regards,
Simeon Simeonov
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Web Services
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Simeon Simeonov
Telerik team
Share this question
or