Serialize EntityFramework Object and Remove Null properties
In the following code, I'm providing a way to serialize an entity object from the EntityFramework taking into consideration the relationships with other entities. I'm providing a way to remove the empty properties, null values and empty arrays from the Json string. First of all, it is important to mention that the following code is applicable only for Newtonsoft API, I'm using JsonConvert.SerializeObject for serialization. Make sure to add a reference to the Newtonsoft.Json.dll. Serialize…