I would like to have a LINQ query that is supposed to return all members with VitalSigns where event in the vital signs is equal to surgery.
My Member.cs
class:
public class Member
{
public int Id { get; set; }
public string FullName { get; set; }
public ICollection<VitalSign> VitalSigns { get; set; }
public Member()
{
VitalSigns = new Collection<VitalSign>();
}
}
And my VitalSign.cs
class is :
public class VitalSign
{
public int Id { get; set; }
public string Event { get; set; }
// relationships
public Member Member { get; set; }
public int MemberId { get; set; }
}
The LINQ query that I wrote is:
return await context. Members.Include(c => c.VitalSigns.Where(t => t.Event == "post surgery")).ToListAsync();
This returns a self-referenced loop. Because there are some data in the VitalSigns
where the event is not equal to "post surgery". Am I writing the query wrong?