简体   繁体   中英

Generic ObjectContext? objectContext.GetObjectSet<TEntity>?

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

Pseudo:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM