I need to return the full json object (including child json objects), however I'm getting an error... The entity was imported from the database.
error
Self referencing loop detected with type 'System.Data.Entity.DynamicProxies.PhoneNumber_C240BC86FA502D917EFDFC445D42023BBD311F87B9B79339114CAC180EEC83F1'. Path '[0].UserProfile.PhoneNumbers[0].PhoneNumberType.PhoneNumbers'.
Entity
[Table("UserProfile")]
public partial class UserProfile
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public UserProfile()
{
PhoneNumbers = new HashSet<PhoneNumber>();
Users = new HashSet<User>();
UserEmails = new HashSet<UserEmail>();
}
public int Id { get; set; }
[Column(TypeName = "datetime2")]
public DateTime? dte_modified { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<PhoneNumber> PhoneNumbers { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<User> Users { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<UserEmail> UserEmails { get; set; }
}
Api Controller
[HttpGet]
[Route("")]
public IHttpActionResult Get()
{
var result = _repository.GetAllUsers();
return Json(result);
}
repository
public IEnumerable<User> GetAllUsers()
{
return _context.Users.ToList();
}