Note that there are some explanatory texts on larger screens.

plurals
  1. POquestion about linq select and ToList()
    primarykey
    data
    text
    <p>I have a problem with returning a list by executing a <code>Select</code> LINQ query. This is the query:</p> <pre><code> var data = Repository&lt;EducationString&gt; .Find() .ToList() .Select(p =&gt; new EducationStringModel() { Id = p.Id, Title = p.Title, EducationDegree=p.EducationDegree }) .ToList(); </code></pre> <p>As you can see I used <code>ToList()</code> 2 times. I don't know why but when I delete the first <code>ToList()</code> I see this error, <em>"Index was outside the bounds of the array"</em>, but by having both <code>ToList()</code> there is no problem.</p> <p>Would it help if I said <code>EducationDegree</code> in <code>EducationStringModel</code> is an <code>IList&lt;EducationDegree&gt;</code>?</p> <p>Is there anybody who knows the reason?</p> <p>@Mark :its L2O</p> <p>if u need to see the classes:</p> <p>public class EducationStringModel { private IList _educationDegree = new List(); public IList EducationDegree { get { if (_educationDegree == null) { _educationDegree = new List(); } return _educationDegree; } set { _educationDegree = value; }</p> <pre><code>} public int? Id { get; set; } public string Title { get; set; } </code></pre> <p>}</p> <p>public class EducationString{</p> <p>private string _title; private IList _educationExperiences; private IList _educationDegree;</p> <pre><code>virtual public string Title { get { return _title; } set { _title = value; } } virtual public IList&lt;EducationExperience&gt; EducationExperiences { get { if (_educationExperiences == null) { _educationExperiences = new List&lt;EducationExperience&gt;(); } return _educationExperiences; } set { _educationExperiences = value; } } virtual public IList&lt;EducationDegree&gt; EducationDegree { get { if (_educationDegree == null) { _educationDegree = new List&lt;EducationDegree&gt;(); } return _educationDegree; } set { _educationDegree = value; } } </code></pre> <p>}</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.
    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