Returning a group by ienumerable

Posts   
 
    
Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 19-Apr-2011 09:19:23   

This is my statment

private IEnumerable<IGrouping<AccountEntity,AxsEntity>> GetAxsEntitiesForInvoicing(IDataAccessAdapter adapter) { var metaData = new LinqMetaData(adapter);

        var query = from axsEntity in metaData.Axs

                    join accountEntity in metaData.Account on axsEntity.AccountId equals accountEntity.AccountId

                    where
                            (axsEntity.DateDeleted.HasValue? axsEntity.DateDeleted.Value<DateTime.Now:true) &&
                            (axsEntity.DateEnd == null || axsEntity.DateEnd > axsEntity.DateRenewal) &&
                            axsEntity.DateRenewal < RenewalDate // NONE INCLUSIVE DATE

                            group axsEntity by accountEntity into axsCol

                    select axsCol;

        return query;

As soon as i try convert this to .ToList() it throws an error.

"The type 'System.Linq.IQueryable1[[<>f__AnonymousType02[[Data.Rad.EntityClasses.AxsEntity, Data.Rad, Version=1.0.4125.30654, Culture=neutral, PublicKeyToken=null],[Data.Rad.EntityClasses.AccountEntity, Data.Rad, Version=1.0.4125.30654, Culture=neutral, PublicKeyToken=null]], Model.Rad, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' can't be converted to an entity type in any way. Did you use a let statement on a group by clause?"

Is there anyway to do this. If I group by in memory it kills my computer.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Apr-2011 10:17:21   

What's the type of the variable you store the return of the ToList() in?

Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 19-Apr-2011 10:35:32   

Well i have about 10000 accounts with each records has +- 10 related records which i retrieve through a join. Now i need to get a IEnumerable of those accounts with the account and the related child records. I am going to change the way i do it tho, will do it using prefetches

Thanks