没有给出对应于 GenericRepository<Incident>.GenericRepository(dbContext) 所需形式参数 'context 的参数
There is no argument given that corresponds to the required formal parameter 'context of GenericRepository<Incident>.GenericRepository(dbContext)
我在尝试从我的 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()
{
}
该错误告诉您您没有调用适当的基本构造函数。派生中的构造函数 class ...
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 does not contain a constructor that takes 0 arguments
我在尝试从我的 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()
{
}
该错误告诉您您没有调用适当的基本构造函数。派生中的构造函数 class ...
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 does not contain a constructor that takes 0 arguments