none
Turn Off Navigation Properties RRS feed

  • Question

  • Using VS 2012, Entity Framework 5 and SQL Server Express 2012.

    I have a SQL Server database to service an application using Web API; as it is mainly for use on mobile devices, I want to minimize data transfer so I would like to disable Navigation Properties. I've setProxyCreationEnabled and LazyLoadingEnabled to false which means that the related data does not get serialized which helps a lot but they are still appearing as empty arrays in the data returned in calls to the Web APIwhich means I will have to handle them some way in the AJAX calls.

    Is there some way to turn them off completely?

    Sunday, February 10, 2013 10:59 AM

Answers

All replies

  • Hi there,

    I have moved this thread to where is the forum for to look for an appropriate forum.

    Thank you for your understanding and support.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 11, 2013 8:05 AM
    Moderator
  • I am afraid no way.

    Ghost,
    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Wednesday, February 13, 2013 3:10 AM
  • Hi,

    You are not forced to expose the entity unchanged, you could expose a version that suits your needs by making not available at all those navigation properties (either by transferring them to another type or perhaps by using inheritance to have a "naked" entity and its descendant with navigation properties).

    I'm new myself to web api but you could perhaps also have a way to tell to ignore transmitting some members (using attributes ?) in which case it could be better to post to an asp.net forum (but feel free to report here for the answer you choosed).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Wednesday, February 13, 2013 12:00 PM
  • @CrazyGhost_Von:

     I am afraid no way.

    This was possible in EF4 as described here; any idea why it isn't possible in EF5?
    Friday, February 15, 2013 10:38 AM
  • @Patrice Scribe:

    You are not forced to expose the entity unchanged ...

    I realise that but I am trying to avoid unnecessary work. This was possible in EF4 as mentioned in my reply to CrazyGhost_Von but it looks like this is another example of an increasingly annoying trend with MS where upgraded versions of software discard useful functionality that was previously available :(

    Friday, February 15, 2013 10:45 AM
  • This is not at the EF level, it was at the WCF level. So if you use WCF you could likely still do the same thing. The problem is that you are now using the Web API. Not sure if you have a similar feature on the Web API.

    Ah, a search gave me http://stackoverflow.com/questions/9664330/change-name-of-inner-objects-for-asp-net-mvc-4-webapi-serialization-xml-json that may worth a try (it seems to allow to honor the same DataMember attributes with the Web API so you should be able to do the same).

    As I said http://forums.asp.net (too bad IMO to have made another site for ASP.NET forums rather than making them part of the MSDN forums) might be a better place to ask as it is related to how the class is exposed to web clients rather than really an EF issue.


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Friday, February 15, 2013 5:06 PM