Solved

Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.List<string>'

Posted on 2013-11-27
6
2,512 Views
Last Modified: 2013-11-27
Hi guys,

How can I get round the above?

if (e.Column.FieldName == "InternalName")
                {


                    using (var InternalRef = new AscentEntities())
                    {
                        List<string> items = new List<string>();

                        items = (from d in InternalRef.HR_Employee select new { d.EmployeeLastName });


                    }


                    //editor.ItemsSource = items;
                }

Open in new window


I thought this may do it

select new items { d.EmployeeLastName });

Open in new window


But that didn't work. I just want a list of strings?!

Thanks,
Dean
0
Comment
Question by:deanlee17
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39680142
try:
   
   items = (from d in InternalRef.HR_Employee select d.EmployeeLastName).ToList();

Open in new window

0
 

Author Comment

by:deanlee17
ID: 39680352
That's about the only thing I didn't try. Cheers mate.
0
 

Author Comment

by:deanlee17
ID: 39680387
How does this differ if I want EmployeeFirstName and EmployeeLastName? As the below errors...

items = (from d in InternalRef.HR_Employee select d.EmployeeLastName d.EmployeeFirstName).ToList();

Open in new window

0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
LVL 42

Expert Comment

by:sedgwick
ID: 39680392
if u want them concatenated then use this:
items = (from d in InternalRef.HR_Employee select (d.EmployeeLastName+" " +d.EmployeeFirstName)).ToList();

Open in new window

0
 

Author Comment

by:deanlee17
ID: 39680585
Perfect thanks
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39680597
u welcome
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question