Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<IRole>'

We have this class defined:

namespace VU.Business.Entities
{
    public class KuDbRoleProvider : IRoleProvider
    {
        public KuDbRoleProvider();

        public IEnumerable<IRole> GetDefaultRoles();
        public IRole GetRoleByName(string roleName);
        public IRole New(string roleName);
        public IEnumerable<IRole> RetrieveAllRoles();
    }
}

And in another class I'm trying to implement and call the RetrieveAllRoles() and put it into some sort of collection which I tried making an array:

    class KURoleProvider : RoleProviderBase
    {
        public override Configuration.Roles.Role[] GetRoles()
        {
           
            KuDbRoleProvider roleProvider;
            BusinessInterfaces.Security.IRole[] kuRoles;
            kuRoles = roleProvider.RetrieveAllRoles();
....

I can't figure out how to get this working.  Here is my error:

 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<BusinessInterfaces.Security.IRole>' to 'BusinessInterfaces.Security.IRole'. An explicit conversion exists (are you missing a cast?)
Avatar of p_davis
p_davis

not that this will fix your problem explicitly but i would recommend using generic lists for this

List<KuDbRoleProvider >
IRole[] is Array. As IEnumerable<T>, they are both IEnumerable. But you cannot convert IEnumerable<T> to Array implicitly. You can declare kuRoles as IEnumerable<IRole>, that will work.
Avatar of dba123

ASKER

why would you use an IEnumerable in the first place to get a list of roles when you can just shove it into a frigging generic list or array?  I don't see why whoever implemented this with an Enumerable.
Avatar of dba123

ASKER

It is pretty obvious, that I need to implement all the methods in the IRoleProvider which it looks like KuDbRoleProvider has not done yet.  It's just stubbed out.  I don't need to create a new class, I just need to finish the implementation on KuDbRoleProvider methods for IRoleProvider it looks like.  I just don't get why anyone would use IEnumerable to get a list of the roles from our DAL when you can just push it into an array in the first place.
Avatar of dba123

ASKER

nevermind I guess I was looking at some meta data of that class.  So here's the implementation of RetrieveAll


        public IEnumerable<IRole> RetrieveAllRoles()
        {
            List<IRole> roles = new List<IRole>();

            using (IDataReaderEnumerable<DAL.Role> dalRoles = DAL.Role.RetrieveAll())
                foreach (DAL.Role dalRole in dalRoles)
                    roles.Add(new Role(dalRole));

            return roles;
        }

Why the hell would you use IEnumerable in this case?  it's returning a generic list in the first place that can be sorted so why would you do that?  and what's this IDataReaderEnumerable...weird, I've never used this before.  I didn't implement this method and the person who did is out right now.
ASKER CERTIFIED SOLUTION
Avatar of dba123
dba123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial