Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
namespace Example.Web.Repositoty
{
    public class CategoryManager : DomainService, ICategoryManager
    {
        private readonly IRepository<Category> _repositoryCategory;
        public CategoryManager(IRepository<Category> repositoryCategory)
        {
            _repositoryCategory = repositoryCategory;
        }
        public async Task<Category> Create(Category category)
        {
            throw new NotImplementedException();
        }
        public void Delete(int Id)
        {
            throw new NotImplementedException();
        }
        public void Update(Category entity)
        {
            throw new NotImplementedException();
        }
        public IEnumerable<Category> GetAllList()
        {
            throw new NotImplementedException();
        }
        public Category GetCategoryById(int Id)
        {
            throw new NotImplementedException();
        }
    }
}



I have hit issue when build.The error message say that:
The type 'Example.Model.Category' cannot be used as type parameter 'TEntity' in the generic type or method 'IRepository<TEntity>'.
 There is no implicit reference conversion from 'Example.Model.Category' to 'Abp.Domain.Entities.IEntity<int>'.	Example.Web

Error at line:
private readonly IRepository<Category> _repositoryCategory;
        public CategoryManager(IRepository<Category> repositoryCategory)
        {
            _repositoryCategory = repositoryCategory;
        }


What I have tried:

I do not know how to solve this problem.Can anyone help me?
Posted
Updated 4-Feb-21 22:49pm

1 solution

The error message is telling you that your Example.Model.Category class needs to implement Abp.Domain.Entities.IEntity<int> if you want to use it as the generic type parameter in your IRepository<TEntity> interface.

Your interface has a constraint on its type parameter - something similar to:
C#
interface IRepository<TEntity> where TEntity : IEntity<int>
Constraints on type parameters - C# Programming Guide | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900