Compile error when calling ToList() when accessing many to many with Linq To Entities

Posted by KallDrexx on Stack Overflow See other posts from Stack Overflow or by KallDrexx
Published on 2010-05-12T03:24:53Z Indexed on 2010/05/12 3:34 UTC
Read the original article Hit count: 428

I can't figure out what I am doing wrong. I have the following method:

    public IList<WObject> GetRelationshipMembers(int relId)
    {
        var members = from r in _container.ObjectRelationships
                      where r.Id == relId
                      select r.WObjects;

        return members.ToList<WObject>();
    }

This returns the following error:

Instance argument: cannot convert from 'System.Linq.IQueryable<System.Data.Objects.DataClasses.EntityCollection<Project.DomainModel.Entities.WObject>>' to 'System.Collections.Generic.IEnumerable<Project.DomainModel.Entities.WObject>'

How can I convert the EntityCollection to a list without lazy loading?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#