JSON.NET Error Self referencing loop detected for type

后端 未结 25 2931
我在风中等你
我在风中等你 2020-11-22 02:16

I tried to serialize POCO class that was automatically generated from Entity Data Model .edmx and when I used

JsonConvert.SerializeObject 

25条回答
  •  长发绾君心
    2020-11-22 02:31

    The simplest way to do this is to install Json.NET from nuget and add the [JsonIgnore] attribute to the virtual property in the class, for example:

        public string Name { get; set; }
        public string Description { get; set; }
        public Nullable Project_ID { get; set; }
    
        [JsonIgnore]
        public virtual Project Project { get; set; }
    

    Although these days, I create a model with only the properties I want passed through so it's lighter, doesn't include unwanted collections, and I don't lose my changes when I rebuild the generated files...

提交回复
热议问题