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

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
deanlee17Asked:
Who is Participating?
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
try:
   
   items = (from d in InternalRef.HR_Employee select d.EmployeeLastName).ToList();

Open in new window

0
 
deanlee17Author Commented:
That's about the only thing I didn't try. Cheers mate.
0
 
deanlee17Author Commented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Meir RivkinFull stack Software EngineerCommented:
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
 
deanlee17Author Commented:
Perfect thanks
0
 
Meir RivkinFull stack Software EngineerCommented:
u welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.