Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with serialization in web api restful service
Message
De
17/06/2016 12:00:52
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01637433
Message ID:
01637459
Vues:
55
J'aime (1)
>>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform