通用ObjectContext?objectContext.GetObjectSet& lt; TEntity& gt ;? [英] Generic ObjectContext? objectContext.GetObjectSet<TEntity>?
本文介绍了通用ObjectContext?objectContext.GetObjectSet& lt; TEntity& gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以获取指定泛型类型的 ObjectQuery< T>
?
Is there a way to get ObjectQuery<T>
for specfied generic type?
伪:
public partial class MyObjectContext
{
public ObjectSet<TEntity> GetObjectSet<TEntity>()
{
return Helper.GetObjectSet<TEntity>(this);
}
}
推荐答案
是的,这是您需要的:
public partial class MyObjectContext
{
public ObjectSet<TEntity> GetObjectSet<TEntity>()
{
return this.CreateObjectSet<TEntity>();
}
}
如您所见,不需要您的辅助方法,因为您可以直接在 MyObjectContext
实例上调用 CreateObjectSet
.它将返回从 ObjectQuery< TEntity>
派生的 ObjectSet< TEntity>
.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.
这篇关于通用ObjectContext?objectContext.GetObjectSet& lt; TEntity& gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文