我从以前的问题,这个代码,但它不是编译:如何解决存储库模式问题这个泛型?
public interface IEntity
{
// Common to all Data Objects
}
public interface ICustomer : IEntity
{
// Specific data for a customer
}
public interface IRepository<T, TID> : IDisposable where T : IEntity
{
T Get(TID key);
IList<T> GetAll();
void Save (T entity);
T Update (T entity);
// Common data will be added here
}
public class Repository<T, TID> : IRepository
{
// Implementation of the generic repository
}
public interface ICustomerRepository
{
// Specific operations for the customers repository
}
public class CustomerRepository : Repository<ICustomer>, ICustomerRepository
{
// Implementation of the specific customers repository
}
但在这两条线:
1-公共类资源库:IRepository
2-公共类CustomerRepository:存储库,ICustomerRepository
它给我这个错误:使用泛型类型'TestApplication1.IRepository'需要'2'类型参数
你能帮我解决吗?
ICustomerRepository在他的代码中是非泛型的。 – 2009-09-30 00:23:29
啊,是的,只是注意到,因为我点击Submit ... – JasonTrue 2009-09-30 00:25:24
现在给出这个错误:类型'T'不能用作通用类型或方法'TestApplication1.IRepository'中的类型参数'T'。没有从'T'到'TestApplication1.IEntity'的装箱转换或类型参数转换。 –
2009-09-30 00:41:19