Dmitry Starchuk's Professional Blog
Development and Architect Experience

Convert IQueryable (result of LINQ select or where or other function) to Generic List List

March 12, 2009 11:44 by Dmitry

 

I tried to cast it directly like this

 

And get error: Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.List<TEntity>'

 

Then I found that it has method to convert to list or cast to object  and it can be either casted to TEntity by calling cast<object> or converted to List<TEntety>

 

By calling .ToList(List<TEntety>)

 

For example here us property :

 

        public List<TEntety> test

        {

            get

            {

                 Return (from tentety in db.TEntety

                            select tentety).ToList<TEntety>();

            }

        }


Currently rated 3.5 by 4 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5