We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

EJ2.AspNetCore struggling with JsonSerializationException

Hello,

I cannot get pastJsonSerializationExceptions when using ef core entities that have cirular references or self references to which many of my models do. I have placed the following line in my startup but this has no effect for syncfusion controls:
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

There are some other solutions like adding [JsonIgnore] to these properties work but this is unworkable because I use database first and often scaffold which removes the attributes. I have also tried usingMetadataType attribute to adorn these properties with [JsonIgnore] but I get a runtime error when doing so indicating that System.ComponentModel.DataAnnotations cannot be loaded. I have also tried ModelMetadataType but that did not work and I don't like the idea of referencing Asp.NetCore in my entity library just to add this attribute.

The only other option would be to create new classes but I would need to pretty much duplicate my whole model and then updating the model I would need to copy the data from the classes to the model classes. This is a lot of work just to get around Json serialisation errors. Is there a possibility of setting an option in the syncfusion library to ignore ReferenceLoopHandling?

3 Replies

MS Madhu Sudhanan P Syncfusion Team December 13, 2018 07:20 AM

Hi Demetrio, 
 
Thanks for contacting Syncfusion support. 
 
Currently we cannot provide serialization settings to the serialization used by EJ2 controls. Using ViewModel concept is the one of the recommended solution to avoid this exception. Also for updating the entity there is no need to use the ViewModel instead you can simply use the original entity class. If you have faced any difficulties in updating please let us know we will be help you out. 
 
Regards, 
Madhu Sudhanan P 



KH Karl Heinz Brehme May 14, 2019 10:51 PM

Hi, is really annoying to have all database in my hand with Context, and simply do a query object with Linq on EntityFramework and I can't bind the result on a grid showing fields from many objects like a normal database query, because we have to build a new class just to show data on a grid and repeat code...

I think Syncfusion could do something to make this more clean in this matter.



HJ Hariharan J V Syncfusion Team May 22, 2019 12:19 PM

Hi Demetrio,

Greetings from Syncfusion,

Currently we do not have support to achieve your requirement “Serialization support for datasource object in ASP.NET Core “ but we have logged a feature request on this and it can be tracked through our feedback portal below.

Link : https://www.syncfusion.com/feedback/6417/serialization-support-for-datasource-object-in-asp-net-core  

If you have any more specification/suggestions to the feature request you can add it as a comment in the portal.

Thanks,
Hariharan 


Loader.
Live Chat Icon For mobile
Up arrow icon