与通用接口混淆
Confused with Generic Interfaces
如有任何帮助,我们将不胜感激。我正在观看关于复数视觉的视频,但我无法弄清楚我做错了什么。我收到这个错误
Error 5 The type 'Domain.Business.Entities.Employee' cannot be used as
type parameter 'T' in the generic type or method
'Core.Common.DataRepositoryBase'. There is no implicit reference
conversion from 'Domain.Business.Entities.Employee' to
'Core.Common.Contracts.IIdentifiableEntity'. C:\Users\ibraheem\Documents\Visual
Studio
2013\Practice\EF_MVC_Practice\Employees.Data\Repositories\EmployeeRepository.cs 11 18 Employees.Data
这就是我的代码的样子
public interface IDataRepository
{
}
public interface IDataRepository<T> : IDataRepository where T : class, IIdentifiableEntity, new()
{
//do stuff
}
public abstract class DataRepositoryBase<T, U> : IDataRepository<T>
where T : class, IIdentifiableEntity, new()
where U : DbContext, new()
{
}
//this is where I get the error
public class EmployeeRepository : DataRepositoryBase<Employee, EmployeesContext>
{
}
编辑:
public class Employee : IIdentifiableEntity
{}
已解决:
EmployeeRepository 从未实现 IIdentifiableEntity
感谢大家的帮助。
已解决:EmployeeRepository
从未实现 IIdentifiableEntity
感谢大家的帮助。
如有任何帮助,我们将不胜感激。我正在观看关于复数视觉的视频,但我无法弄清楚我做错了什么。我收到这个错误
Error 5 The type 'Domain.Business.Entities.Employee' cannot be used as type parameter 'T' in the generic type or method 'Core.Common.DataRepositoryBase'. There is no implicit reference conversion from 'Domain.Business.Entities.Employee' to 'Core.Common.Contracts.IIdentifiableEntity'. C:\Users\ibraheem\Documents\Visual Studio 2013\Practice\EF_MVC_Practice\Employees.Data\Repositories\EmployeeRepository.cs 11 18 Employees.Data
这就是我的代码的样子
public interface IDataRepository
{
}
public interface IDataRepository<T> : IDataRepository where T : class, IIdentifiableEntity, new()
{
//do stuff
}
public abstract class DataRepositoryBase<T, U> : IDataRepository<T>
where T : class, IIdentifiableEntity, new()
where U : DbContext, new()
{
}
//this is where I get the error
public class EmployeeRepository : DataRepositoryBase<Employee, EmployeesContext>
{
}
编辑:
public class Employee : IIdentifiableEntity
{}
已解决: EmployeeRepository 从未实现 IIdentifiableEntity
感谢大家的帮助。
已解决:EmployeeRepository
从未实现 IIdentifiableEntity
感谢大家的帮助。