EntityCollection - lack of IEnumerable<T> is annoying

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 18-Aug-2009 05:32:51   

I have an entitycollection that I want to decouple from the ORMSupportClasses by moving it's contents to a List<T>.

But for some reason EntityCollection doesn't implement IEnumerable<T>. Something that frequently annoys me. With what is avialable atm this is the shortest way I have found to get a List<T>


IEnumerable<Shivam.SugarCube.DAL.Model.IRole> Shivam.SugarCube.DAL.Model.IUser.Roles
        {
            get {
                var c = new RoleEntity[RoleCollectionViaUserRole.Count];
                RoleCollectionViaUserRole.CopyTo(c, 0);
                return new List<Shivam.SugarCube.DAL.Model.IRole>(c);
            }
        }

Anyway to make this a one-liner?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Aug-2009 06:51:10   

The collection does implement IEnumerable. You are using v2.6 and .Net35. So, any of this line should work:

IList<RoleEntity> roleList= RoleCollectionViaUserRole;
IList<RoleEntity> roleList = RoleCollectionViaUserRole.ToList();
IEnumerable<RoleEntity> roleList = RoleCollectionViaUserRole.ToList();
David Elizondo | LLBLGen Support Team
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 18-Aug-2009 07:41:31   

Crap, still havent mastered extension methods. Forgot to add System.Linq... I do this all the time rage

So I have this:


return RoleCollectionViaUserRole.Cast<Shivam.SugarCube.DAL.Model.IRole>().ToList();

This might be a silly question but if i add a RoleEntity to what I return it's not going to add it to the original RoleCollectionViaUserRole instance is it?

Thanks daelmo.

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 18-Aug-2009 07:59:20   

I made a class that wraps an IList and implements IList<T>. Now I have a member on my entityclass that looks like this:


        IList<Shivam.SugarCube.DAL.Model.IUserRole> Shivam.SugarCube.DAL.Model.IUser.UserRoleUsingUserId{
            get{
                return (IList<Shivam.SugarCube.DAL.Model.IUserRole>)new Shivam.SugarCube.DAL.Model.ListWrapper<Shivam.SugarCube.DAL.Model.IUserRole>(UserRoleUsingUserId);
            }
        }

And i should able to add to it without any issues. Now I can deal with my UserEntity (for example) as IUser/


public interface IUser  {   
    
    // __LLBLGENPRO_USER_CODE_REGION_START UserRoleUsingUserIdAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    IList<IUserRole> UserRoleUsingUserId{ get; }

    
    // __LLBLGENPRO_USER_CODE_REGION_START RoleCollectionViaUserRoleAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    IList<IRole> RoleCollectionViaUserRole{ get; }



    
    // __LLBLGENPRO_USER_CODE_REGION_START UserIdAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.Int32 UserId { get;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START UsernameAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.String Username { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START PasswordAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.String Password { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START FirstNameAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.String FirstName { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START SurnameAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.String Surname { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START EmailAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.String Email { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START IsActiveAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.Boolean IsActive { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START LastLoginAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.DateTime? LastLogin { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START UpdatedOnAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.DateTime UpdatedOn { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START UpdatedByAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.String UpdatedBy { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START CreatedOnAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.DateTime CreatedOn { get;set;}
    
    // __LLBLGENPRO_USER_CODE_REGION_START CreatedByAttributes
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.String CreatedBy { get;set;}
    
    }

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 18-Aug-2009 09:52:15   

Thanks for the feedback.