当我试图从我的GenericRepository继承时,我得到了这个错误信息。错误提示我还需要提供上下文,但我不确定如何提供?
//IncidentRepository
public class IncidentRepository : GenericRepository<Incident>
//Generic Repository (to inherit from)
public class GenericRepository<TEntity> where TEntity : class
{
internal db_SLee_FYPContext context;
internal DbSet<TEntity> dbSet;
public GenericRepository(db_SLee_FYPContext context)
{
this.context = context;
this.dbSet = context.Set<TEntity>();
}
编辑:
只是为了检查我是否掌握了这个?
public class IncidentRepository: GenericRepository<Incident>
{
public IncidentRepository(db_SLee_FYPContext context)
{
this.context = context;
}
//Then in my genric repository
public GenericRepository()
{
}
发布于 2015-11-16 05:18:23
该错误告诉您没有调用适当的基构造器。派生类中的构造函数...
public IncidentRepository(db_SLee_FYPContext context)
{
this.context = context;
}
..。实际上是这样做的:
public IncidentRepository(db_SLee_FYPContext context)
: base()
{
this.context = context;
}
但是没有无参数的基构造器。
您应该通过调用匹配的基构造器来修复此问题:
public IncidentRepository(db_SLee_FYPContext context)
: base(context)
{ }
在C# 6中,如果基本类型中只有一个构造函数,则会收到此消息,因此它会给出基本构造函数中缺少哪个参数的最佳提示。在C# 5中,消息简单地是
GenericRepository不包含采用0个参数
的构造函数
https://stackoverflow.com/questions/33701210
复制相似问题