Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, you should change your entities, to support your relationships:</p> <pre><code>public class Person { public int PersonId { get; set; } public string Forename { get; set; } public string Surname { get; set; } // add a collection-reference to roles public virtual ICollection&lt;Role&gt; Roles { get; set; } // add a collection-reference to visites public virtual ICollection&lt;Visit&gt; Visits { get; set; } } </code></pre> <hr> <pre><code>public class Visit { public int VisitId { get; set; } public string Name {get; set;} public string VisitStatus { get; set; } public int PersonId { get; set; } public virtual Person People { get; set; } //There is a one to many relationship to person } </code></pre> <hr> <pre><code>public class Role { public Role() { People = new HashSet&lt;Person&gt;(); } [Key] public int RoleId { get; set; } public string Name { get; set; } public virtual ICollection&lt;Person&gt; People { get; set; } //There is a many to many relationship to person } </code></pre> <p>Your problem resolved now. But you can also change the query like this:</p> <pre><code>public IEnumerable&lt;VisitDetails&gt; GetGuestVisiterList(int paperId) { using (var db = _dbFactory.GetDatabase()) { return (from p in db.People where p.Roles.Any(a =&gt; a.Name == "Guest") select new GuestVisitDetails { PersonId = p.PersonId, Forename = p.Forename, Surname = p.Surname, NumberOfVisits = p.Visits.Count(v =&gt; v.VisitStatus != "Complete") }).ToList(); } } </code></pre> <p>Let me know if you have any problem or questions or need clarifications on any part. Cheers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload