Ank*_*oel 2 generics reflection entity-framework
public partial class GridMastercontrol<TEntity> : UserControl
{
private System.Data.Objects.ObjectSet<TEntity> _osMain; // error here
}
Run Code Online (Sandbox Code Playgroud)
我无法声明泛型类型的对象集.请帮我怎么做.
错误消息是 - 'TEntity'类型必须是引用类型才能在泛型类型或方法'System.Data.Objects.ObjectSet'中将其用作参数'TEntity'
将通用约束添加到类声明中:
public partial class GridMastercontrol<TEntity> : UserControl where TEntity : class
Run Code Online (Sandbox Code Playgroud)
你必须这样做,因为ObjectSet<TEntity>已经有一个:
public class ObjectSet<TEntity> : ObjectQuery<TEntity>,
IObjectSet<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>,
IQueryable, IEnumerable
where TEntity : class
Run Code Online (Sandbox Code Playgroud)