0

I need get all roles use roleManager.Roles. I get Exception "does not implement IQueryableRoleStore", and add to my class RoleStore. And I don't know how to implement this property.Please help

public IQueryable<TRole> Roles
        {
            get { return }
        }

My class

public class RoleStore<TRole> : IRoleStore<TRole>, IQueryableRoleStore<TRole>, IDisposable where TRole : RoleEntity
    {
private readonly IDependencyResolver resolver;
        private readonly ILogger<RoleStore<TRole>> logger;
        private readonly IExceptionManager exceptionManager;
        private readonly IRolesRepository rolesRepository;
        private readonly IUnitOfWork unitOfWork;
#region IRoleStore<TRole> Implementation


        public Task CreateAsync(TRole role)
        {
            if ((object)role == null)
                throw new ArgumentNullException("role");

            logger.Debug("Create role {0} requested...", role.Name);
            try
            {
                unitOfWork.ExecuteTransactional(() =>
                {
                    rolesRepository.Insert(role);
                });

                logger.Debug("Create role {0} completed...", role.Name);
                return Task.FromResult(role);
            }
            catch (Exception e)
            {
                bool rethrow = true; logger.Error(e, "Fatal Error.");
                if (rethrow)
                {
                    throw e;
                }
            }

            return Task.FromResult((TRole)null);
        }

        public Task DeleteAsync(TRole role)
        {
            throw new NotImplementedException();
        }

        public Task<TRole> FindByIdAsync(string roleId)
        {
            logger.Debug("Find by id async for role {0} requested...", roleId);
            try
            {
                return Task.FromResult(
                    (TRole)rolesRepository.GetById(roleId)
                );
            }
            catch (Exception e)
            {
                bool rethrow = true; logger.Error(e, "Fatal Error.");
                if (rethrow)
                {
                    throw e;
                }
            }

            return Task.FromResult((TRole)null);
        }

        public Task<TRole> FindByNameAsync(string roleName)
        {
            logger.Debug("Find by name async for role {0} requested...", roleName);
            try
            {
                return Task.FromResult(
                    (TRole)rolesRepository
                        .Specify<IRoleSpecification>()
                        .WithRoleName(roleName)
                        .ToResult()
                        .SingleOrDefault()
                );
            }
            catch (Exception e)
            {
                bool rethrow = true; logger.Error(e, "Fatal Error.");
                if (rethrow)
                {
                    throw e;
                }
            }

            return Task.FromResult((TRole)null);
        }

        public Task UpdateAsync(TRole role)
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            GC.SuppressFinalize((object)this);
        }

        public IQueryable<TRole> Roles
        {
            get { return }
        }
        #endregion
Tomoko
  • 3
  • 2
  • Can you provide a more detailed example of your class instead of just the property you want to implement? Especially specify the class variables and the class signature. – Sil Aug 05 '22 at 06:22
  • If you're using a `DbContext` as the source for the roles then it's probably going to be something like `return dbContext.Roles.AsQueryable();`. – user18387401 Aug 05 '22 at 06:26
  • If you are doing your own implementation of `IQueryableRoleStore` then how completely depends on what storage layer (if nay) you are using. – Richard Aug 05 '22 at 06:31
  • @Sil, i added details – Tomoko Aug 05 '22 at 06:43

1 Answers1

1

The public IQueryable<TRole> Roles is waiting the list of roles you want to return. You should return the roles from your Repository. If you do not have a GetRoles() implement it.

It should look like this.

public IQueryable<TRole> Roles
{
     get
    {
       return _roleRepository.GetRoles();
    }
}
Max
  • 794
  • 3
  • 7