Stack Exchange
How to Include objects in entityframework using a repository?
Im fetching a "Paste" from a Repository with the function bellow, but i cant access objects that should be included when i fetch the Paste. (Paste.FilterGroup.Ads).
My Repository function:
    public T Find<T>(Expression<Func<T, bool>> predicate) where T : class
    {
        return Context.Set<T>().FirstOrDefault<T>(predicate);
    }

And in my code i try this. 
                oPaste = _repository.Find<Paste>(x => x.PasteID == oPaste.PasteID);

            if (oPaste.FilterGroup != null)
            {
                _log.Debug("FilterGroup: " + oPaste.FilterGroup.Name);

                if (oPaste.FilterGroup.Ads != null && oPaste.FilterGroup.Ads.Count() > 0)
                {
                    _log.Debug("FINALLY");
                }
                else
                {
                    _log.Debug("Paste " + oPaste.PasteID + " has no ads");
                }
            }
            else
            {
                _log.Debug("Paste " + oPaste.PasteID + " has no filtergroup");
            }

Edit:
 Paste Class Contains
public virtual FilterGroup FilterGroup { get; set; }

FilterGroup Class Contains
public virtual IEnumerable<Ad> Ads { get; set; }


You must replace
public virtual IEnumerable<Ad> Ads { get; set; }

by
public virtual ICollection<Ad> Ads { get; set; }

or some other collection type that implements ICollection<T>. IEnumerable<T> does not and EF will ignore it as navigation property.
As long as your context is alive your navigation properties should be loaded then by lazy loading.
You could also support eager loading in your repository:
using System.Data.Entity; // required for the lambda version of Include

// ...

public T Find<T>(Expression<Func<T, bool>> predicate, 
    params Expression<Func<T, object>>[] includes) where T : class
{
    IQueryable<T> query = Context.Set<T>();

    if (includes != null)
        foreach (var include in includes)
            query = query.Include(include);

    return query.FirstOrDefault<T>(predicate);
}

And then call it like so:
oPaste = _repository.Find<Paste>(x => x.PasteID == oPaste.PasteID,
    x => x.FilterGroup.Ads);

