請幫助我更正此代碼。在接口中使用通用方法
我在班上
public interface IGenericSaveRepository
{
void Save<TEntity>(int id, ICollection<TEntity> entities) where TEntity : class;
}
public class GenericSaveRepository<TEntity> where TEntity : class,IGenericSaveRepository
{
private IUnitofWork<TEntity> _unitofWork;
private NaijaSchoolsContext _context;
public GenericSaveRepository(NaijaSchoolsContext context)
{
_context = context;
_unitofWork = new UnitofWork<TEntity>(_context);
}
public void Save(int id, ICollection<TEntity> entities)
{
foreach (var entity1 in entities)
{
//entity.Insert(entity1);
_unitofWork.Entity.Insert(entity1);
}
}
}
public class RatingRepo : GenericRepository<Rating>
{
private IGenericSaveRepository gen;
private readonly NaijaSchoolsContext _context;
public RatingRepo(NaijaSchoolsContext context)
: base(context)
{
_context = context;
}
public void Save(School school,Rating rating)
{
List<Rating> ratings = new List<Rating>();
ratings.Add(rating);
gen = new GenericSaveRepository<Rating>(_context);
gen.Save(23, ratings);
}
}
此行gen = new GenericSaveRepository<Rating>(_context);
不允許我有指定爲具體型別等級有編譯器錯誤。
我該怎麼做?
感謝您的幫助。
確實評級實施IGenericSaveRepository? – 2014-10-20 11:30:36
GenericRepository和GenericSaveRepository 之間是否有區別或者是否是拼寫錯誤? 此外,評級的代碼缺失,請proivde。 –
mindfxxxedCoder
2014-10-20 11:34:09
不,它不執行它@ Selman22 – Seun 2014-10-20 11:35:15