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