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":[