开发者

Generic ObjectContext? objectContext.GetObjectSet<TEntity>?

Is there a way to get ObjectQuery<T> for specfied generic type?

Ps开发者_开发百科eudo:

public partial class MyObjectContext
{
    public ObjectSet<TEntity> GetObjectSet<TEntity>()
    {
        return Helper.GetObjectSet<TEntity>(this);
    }
}


Yes this is what you need:

public partial class MyObjectContext
{
    public ObjectSet<TEntity> GetObjectSet<TEntity>()
    {
        return this.CreateObjectSet<TEntity>();
    }
}

As you can see your helper method is not needed because you can call CreateObjectSet directly on MyObjectContext instance. It will return ObjectSet<TEntity> which is derived from ObjectQuery<TEntity>. TEntity must be mapped type and it cannot be derived type in entity hierarchy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜