0

In asp.net core, I can get list if I don't include object. But can't get list of data if I include a object with it.

I have tried both code first and database first approach. Results are same.

public partial class BloodGroups
{
    public BloodGroups()
    {
        Donors = new HashSet<Donors>();
    }
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Donors> Donors { get; set; }
}

public partial class Donors
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int? BloodGroup { get; set; }
    public virtual BloodGroups BloodGroupNavigation { get; set; }
}

public async Task<ActionResult<IEnumerable<Donors>>> GetDonors()
{
    return await _context.Donors.Include(d => d.BloodGroupNavigation).ToListAsync();
}

I have created a web API project using asp.net core in visual studio 2019. I have created two model with one to many relationship. Then I had created a async call to get all donors list. It gives me all data. But if I include BloodGroups object with it, It shows first data, then the object of BloodGroup with incomplete donors list. This is the result:

[{"id":1,"name":"Robiul","bloodGroup":2,"bloodGroupNavigation": 
{"id":2,"name":"B+","donors":[
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Robiul
  • 55
  • 6
  • 3
    This looks like a [`ReferenceLoopHandling`](https://stackoverflow.com/questions/11979637/what-does-referenceloophandling-ignore-in-newtonsoft-json-exactly-do) issue. It's essentially just a circular reference problem. – Kirk Larkin Aug 10 '19 at 10:46
  • yeah. that was the problem. i've solved it. thanks @KirkLarkin – Robiul Aug 10 '19 at 11:00

0 Answers0