1

I have a generic repository and I am having some trouble with the Include extension method. My repository looks like this:

public class Repository<TEntity> : IRepository<TEntity> {
    private IDbSet<TEntity> _entitySet;

    /*
        some init code
    */

    public TEntity GetByKey(params object[] keys) {
        return _entitySet.Find(keys);
    }

    /*
        more db query methods
    */

    public IRepository<TEntity> Include(Expression<Func<TEntity, object>> selector) {
        _entitySet = _entitySet.Include(selector) as IDbSet<TEntity>;
        return this;
    }
}

This is supposed to be called something like this:

var blogRepository = new Repository<Blog>();
var blogEntry = blogRepository
    .Include(b => b.Posts)
    .Include(b => b.Someothercollection)
    .GetByKey(1);

The problem here is that when I cast the return value of Include in my repository to IDbSet<> I always get null. I must be doing something wrong but I am not sure what. Any ideas?

Thanks

anon
  • 4,578
  • 3
  • 35
  • 54
Alaa Masoud
  • 7,085
  • 3
  • 39
  • 57
  • 1
    I think I have just answered your question on MSDN: http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/596363b4-436e-43c9-a280-7f5ae63ba49f – Ladislav Mrnka Mar 26 '11 at 23:15
  • http://stackoverflow.com/questions/5376421/ef-including-other-entities-generic-repository-pattern/5376637#5376637 ? – BrokenGlass Mar 26 '11 at 23:16

0 Answers0