Best described with an example, so i'll jump straight into an example model and code below to illustrate my question.
Models:
public class MyModel
{
public int Id { get; set; }
public virtual ICollection<MySecondModel> MySecondModels { get; set; }
}
public class MySecondModel
{
public int Id { get; set; }
public int Counter { get; set; }
}
In my Controller, i want to get a sum of the Counter from MySecondModel, who all relates to MyModel.
I currently have
var person = await db.Persons.Select(i =>
new PersonDTO()
{
Id = i.Id,
Counter = i.MySecondModels.FirstOrDefault().Counter
}).SingleOrDefaultAsync(i => i.Id == id);
But this obviously only gets me the value from the first, and not all of them.
Any ideas?