I am trying to implement Unit of Workin my project and ask some quick questions. I use the class shown in this tutorial :
So, when I implement it and say that I am doing the Users a class GenericRepository. What if there are some elements that I want to add to the class Users, but not part GenericRepository.
How to create another interface and use some type of inheritance, so I'm still getting the stuff from GenericRepositoryalong with the new features that I wanted.
I basically want to expand it.
public interface ICategoryRepository : IGenericRepository<Category>
{
IEnumerable<LocalComicCategoriesModel> GetCategories();
IEnumerable<LocalComicCategoriesModel> GetCategoriesByComicID(int comicid, bool appendCategories);
}
public class CategoryRepository : GenericRepository<Category>, ICategoryRepository
{
new ComicEntities context;
public CategoryRepository(ComicEntities context) : base(context)
{
this.context = context;
}
public IEnumerable<LocalComicCategoriesModel> GetCategories()
{
return context.Categorys.Select(i => new LocalComicCategoriesModel { Id = i.Category_Id, Title = i.Name });
}
public IEnumerable<LocalComicCategoriesModel> GetCategoriesByComicID(int comicid, bool appendCategories)
{
if (appendCategories == true)
{
IEnumerable<LocalComicCategoriesModel> query = from tbcat in context.Categorys
join tbitem_cat in context.ComicCategorys.Where(i => i.Comic_Id == comicid)
on tbcat.Category_Id equals tbitem_cat.Category_Id into ct
from tbitem_cat in ct.DefaultIfEmpty()
select new LocalComicCategoriesModel
{
Id = tbcat.Category_Id,
Title = tbcat.Name,
isChecked = tbitem_cat == null ? false : true
};
return query;
}
else
{
IEnumerable<LocalComicCategoriesModel> returnedCategories = from t in context.Categorys
join v in context.ComicCategorys on t.Category_Id equals v.Category_Id
where v.Comic_Id == comicid
select new LocalComicCategoriesModel
{
Id = v.Category_Id,
isChecked = true,
Title = t.Name
};
return returnedCategories;
}
}
}
Why am I getting this error:
'Comics.Models.Category' cannot be used as type parameter 'TEntity' in the generic type or method 'Comics.DAL.Interfaces.GenericRepository<TEntity>'. There is no implicit reference conversion from 'Comics.Models.Category' to 'Comics.DAL.Interfaces.IGenericRepository<Comics.Models.Category>'.
source
share