Solved

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

Posted on 2013-11-27
6
2,385 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now