Entity to json error - A circular reference was detected while serializing an object of type

前端 未结 5 1035
醉梦人生
醉梦人生 2021-01-02 02:22

Following error occurred when trying to convert entity object into JSON String. I\'m using C# MVC4 with code first DB designing. It seams its because FKs and relationships b

5条回答
  •  心在旅途
    2021-01-02 02:29

    it is trying to load child objects and it may be creating some circular loop property that will never end.

    also you use [ScriptIgnore] , will not serialize the public property or public field look at this :

       public class BookingHotel : IntBaseEntity            
        {    
            public string BookingName { get; set; }    
            public string BookingReference { get; set; }    
            public DateTime? CheckInDate { get; set; }    
            public DateTime? CheckOutDate { get; set; }    
            public int HotelId { get; set; }    
            [ScriptIgnore]    
            public Hotel Hotel { get; set; }        
         }         
    

提交回复
热议问题