Q: Get list of select items from database and populate objects I am trying to Populate an object inside another object while avoiding two things:


*

*Getting all the items in table

*Making a separate call to the db for each item


Here is my code 
Classes 
public class Profile: BaseEntity
{
    public Picture Picture { get; set; }
    public string Name { get; set; }
}

public partial class Picture : BaseEntity
{
   public string Name {get; set;}
}

Services
public class ProfileService : IProfileService
{
    private readonly IRepository<Profile> _profileRepo;
    private readonly IRepository<Picture> _pictureRepo;


     public ProfileService(IRepository<Profile> profileRepo, IRepository<Picture> pictureRepo)
     {
         _profileRepo = profileRepo;
         _pictureRepo = pictureRepo;
     }

     public IEnumerable<Profile> GetProfiles()
     {
          IEnumerable<Profile> profiles = _profileRepo.Table.ToList();
          // I am guessing I would retrieve pictures here based off of picture 
          // ids that are in the profiles   
          // than I would populate the profiles with the pictures
     }
}

Also in the database PictureId is a foreign key in Profile table. 

A: If there is a relation between the objects then you should be able to just create a method in your repository to do:
public IEnumerable<Profile> GetAllProfilesWithPictures()
{
    return your_context.Profiles.Include(x => x.Picture);
}

This will return all the profiles, along with their picture.
Not quite sure on what you mean when you say Getting all items in table..  If you want to limit what you get then you can put a where clause or whatever on the above statement.
