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

2 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 09 May Link to this post

    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?
  2. Simeon Simeonov
    Admin
    Simeon Simeonov avatar
    24 posts

    Posted 12 May Link to this post

    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.
  3. DevCraft banner
Back to Top