Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Query Result to List<T> mapping
    primarykey
    data
    text
    <p>In my database I have 2 tables:</p> <pre><code>id | name | city | street ------------------------------- 1 | John | London | Street1 2 | Will | London | Street1 3 | Adam | LA | Street1 id | uid | phone ------------------ 1 | 1| 12345 2 | 1| 23456 3 | 2| 16505 4 | 3| 65909 5 | 3| 68902 6 | 3| 15905 </code></pre> <p>I need to select that data and store into List (or Dictionary as user Id is unique)</p> <p>My uses class looks like so:</p> <pre><code>public class User { //lock private static readonly object userLock = new object(); public int Id { get; set; } public string Name { get; set; } public string City { get; set; } public string Street { get; set; } public List&lt;string&gt; Phones { get; private set; } public User() { Phones = new List&lt;string&gt;(); } public void AddPhone(string phone) { lock (userLock) { Phones.Add(phone); } } } </code></pre> <p>Idea is to load those users info into application, add/remove/modify phones and save those changed/removed/added.</p> <p>I found idea for solution here: <a href="https://stackoverflow.com/a/11687743/965722">https://stackoverflow.com/a/11687743/965722</a>, but I imagine this as doing one query to get users list and then for each user I need separate query to get his phones.</p> <p>How should I do my loading?<br> Can I do it with only one query?<br> How should I populate my result collection?<br> Should I use List or Dictionary? Then I could remove <code>Id</code> from User class and have it as key inside dictionary.</p> <p>I'm using .NET 3.5 and would like to avoid Entity Framework or ORM's.</p>
    singulars
    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.
 

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