Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with serialization in web api restful service
Message
 
 
À
17/06/2016 12:00:52
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01637433
Message ID:
01637462
Vues:
49
>>>I removed the reference to ProfileSettings from measurement and now it works fine. However, that raises another question. How can I know set the FK releationship between the 2 files, if I can't specify the relationsship?
>>
>>This is how our models are set up in terms of foreign keys (all our models are auto-generated by the Reverse POCO generator):
>>
>>
>> // Foreign keys
>>        public virtual ExportJobs ExportJobs { get; set; } // FK_ExportJobs_AccountingExportJobs_ExportJobsId
>>
>>
>>Also, we have separated the models in its separate project and the web project uses view models and not models directly. In the view models you don't have to use foreign keys.
>>
>>In your case you seems to be missing 'virtual' keyword. See if adding it will make a difference.
>
>I think virtual is only required if lazy loading is needed. He can also turn off circular reference serialization through the following command:
>
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Re‌​ferenceLoopHandling = ReferenceLoopHandling.Ignore;
>This is a global setting which could be set in the Application_Start.
>
>Another way to handle it would be to add a [JsonIgnore] attribute to the navigation properties to prevent them from being serialized.
>
>Both of these methods address Json output only, so if Xml is being used at all, a different approach may be necessary.

Very nice, thanks, Rob. I was wondering where you're when you're needed.

I found this - is it related?

http://stackoverflow.com/questions/12505141/only-using-jsonignore-during-serialization-but-not-deserialization

In our case we have one object right now where we defined many extra properties which we only need to read, but not write to. I was actually proposing to move these properties to completely separate object and read only once, but I haven't worked on that page for some time and my colleagues didn't get around to it. That may be a quick fix for now.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform