Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make a class Phone and change the User property accordingly:</p> <pre><code>public class Phone { public int Id { get; set; } public int UserId { get; set; } public string Number { get; set; } } public class User { // (etc) public List&lt;Phone&gt; Phones { get; set; } // (etc) } </code></pre> <p>Make a PhoneRepository:</p> <pre><code>public class PhoneRepository { public List&lt;Phone&gt; LoadPhonesFromId(IEnumerable&lt;int&gt; ids) { // write a query with the ids // SELECT * FROM Phones WHERE id IN (@id1, @id2, ...) // execute the query // convert the results to Phones and put them in a List&lt;Phone&gt; // return the list } public List&lt;Phone&gt; LoadPhonesFromUserId(IEnumerable&lt;int&gt; userIds) { // write a query with the userIds // SELECT * FROM Phones WHERE userId IN (@userId1, @userId2, ...) // execute the query // convert the results to Phones and put them in a List&lt;Phone&gt; // return the list } } </code></pre> <p>And a UserRepository:</p> <pre><code>public class UserRepository { public List&lt;User&gt; LoadUsersFromUserIds(IEnumerable&lt;int&gt; userIds) { // write a query with the userIds // SELECT * FROM User WHERE id IN (@id1, @id2, ...) // execute the query // convert the results to Users and put them in a List&lt;User&gt; // return the list } public void IncludePhones(IEnumerable&lt;User&gt; users) { var phones = PhoneRepository.LoadPhonesFromUserId (users.Select(x =&gt; x.Id)); for each(var user in users) { user.Phones = phones .Where(x =&gt; x.UserId == user.Id) .ToList(); } } } </code></pre> <p>You can greatly expand and improve on this pattern with, for example, custom filter parameters (instead of different functions for the various filters) and property setters that make sure the user and user.Phones keep referring to the same userID, but that is sort of beyond the scope of your question.</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.
    3. 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