This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am building a Web API 2 (System.Web.Http.ApiController) service on top of a LightSpeed entity model. When the controller converts an EF entity to JSON, it includes all the fields. When it converts a LightSpeed entity, however, it only includes the ID field. Here is the code snippet.
Here is the JSON result.
Is there a setting in LightSpeed model that prevents the controller from accessing other fields? |
|
|
If I decorate the controller as a BreezeController,
I get 2 extra internal fields, like this,
I want to get regular fields, like Name, Description, etc. |
|
|
I believe Web API 2 uses Json.NET to serialize objects.
I am puzzled why Json.NET only includes LightSpeed entity's Id property, which is defined in base class Entity<T>, and ignores all properties defined in child classes. |
|
|
Add a reference to System.ServiceModel to your model assembly which will trigger generation of the DataContract/DataMember attributes which are needed to opt-in for serialization.
|
|
|
Thank you Jeremy for pointing me at the right direction! If I decorate a field with [System.Runtime.Serialization.DataMember], it gets into Json object. System.ServiceModel assembly is not necessary. However, I have to decorate every field manually. Is there an easy way to do it at entity level, or even model level? |
|
|
If you add a reference to System.ServiceModel to your model assembly and regenerate the code for your model then we will append these attributes automatically for you.
|
|
|
Thanks! System.ServiceModel resolves the issue. |
|