开发者

EF CTP5 - IDbSet.Include

I have a generic repository and I am having some trouble with the Include extension method. My rep开发者_如何学编程ository 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜