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 set
ProxyCreationEnabled 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 API which means I will have
to handle them some way in the AJAX calls.
I don't believe that you can completely disable the Navigation properties, but if you are receiving empty array values (instead of your related data) then I would say that you have successfully done what you were trying to (by not pulling your
data).
You may be able to use the [JsonIgnore] attribute to avoid serializing your empty collection so that it doesn't appear within your result set (avoiding you having to handle it)
as mentioned in
this discussion. (Additional Information Here)
M_Harran
Member
1 Points
2 Posts
Turn Off Navigation Properties
Feb 16, 2013 09:34 AM|LINK
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 set ProxyCreationEnabled 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 API which means I will have to handle them some way in the AJAX calls.
Is there some way to turn them off completely?
Rion William...
All-Star
27876 Points
4611 Posts
Re: Turn Off Navigation Properties
Feb 16, 2013 02:26 PM|LINK
I don't believe that you can completely disable the Navigation properties, but if you are receiving empty array values (instead of your related data) then I would say that you have successfully done what you were trying to (by not pulling your data).
You may be able to use the [JsonIgnore] attribute to avoid serializing your empty collection so that it doesn't appear within your result set (avoiding you having to handle it) as mentioned in this discussion. (Additional Information Here)
M_Harran
Member
1 Points
2 Posts
Re: Turn Off Navigation Properties
Feb 19, 2013 01:49 PM|LINK
Okay, Rion, looks like I will just have to do some extra work myself, I guess you can't really expect a wizrd to do everything