Reputation: 5212
I have searched in google for 3 days without any success.
I am using the Database First approach then generated the classes. What I need to do now is to Serialize my entity into Json and then either save to a file or send to another party using Web API (certainly they will be deserialized and consumed later)
The problem here is that EF6 trying to includes all the Navigation Properties, and makes the serialization / deserialization extremely difficults. Setting the properties below doesn't work at all.
Configuration.LazyLoadingEnabled = false;
Configuration.ProxyCreationEnabled = false;
Is there an easy way telling EF6 to just ignore those Navigation Properties all together when serializing? Since I am using the DB first approaches, I have access to all related tables with their foreign keys.
Thanks in Advance.
Upvotes: 0
Views: 481
Reputation: 1512
Try using Newtonsoft.Json;
nuget for the serialization.
To serialize:
string json = JsonConvert.SerializeObject(MyObjects, Formatting.Indented);
Inside your class MyObject
, you just add a [JsonIgnore]
annotation above properties you want to skip (Navigation props among others)
Upvotes: 1