开发者

EF CTP5 - IDbSet.Include

开发者 https://www.devze.com 2023-02-20 13:31 出处:网络
I have a generic repository and I am having some trouble with the Include extension method. My rep开发者_如何学编程ository looks like this:

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

精彩评论

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

关注公众号