Solved

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

Posted on 2013-11-27
6
2,437 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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