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.
精彩评论