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

Related posts

Comments

April 24. 2009 02:09

Effective

I have never encountered such a problem, but you have done an excellent job and were able to fix the error.

Effective

October 25. 2009 06:19

fast cash loans

I always wanted to write in my site something like that but I guess you'r faster Smile

fast cash loans

November 28. 2009 22:34

paydayloans

I guess there's always an easier way ...

paydayloans

November 29. 2009 01:41

online game

I really enyojed this gorgeous blog post. Please keep up the good work. Cheers!.

online game

Comments are closed