Include , Using Set<T>().Where ... RRS feed

  • Question

  • Hi

    I am trying to use generics to return a list of entities. However I would like to return the first level items also. 

    In normal (non generic) link one can use the .Inclue, .Include .... keyword to return child records. How can I do this in this example below?

            public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
                IQueryable<T> query = _entities.Set<T>().Where(predicate);
                return query;

    I.W Coetzer

    • Edited by I.W Coetzer Monday, November 10, 2014 8:50 PM
    Monday, November 10, 2014 7:44 PM


  • Hi. You should be able to use Include as the return type is IQueryable<T>. The QueryableExtensions class is under the System.Data.Entity namespace so you will need a using statement to it in the calling code.
    • Marked as answer by Fred Bao Friday, November 21, 2014 7:46 AM
    Tuesday, November 11, 2014 12:36 AM