• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2594
  • Last Modified:

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
0
deanlee17
Asked:
deanlee17
  • 3
  • 3
1 Solution
 
Meir RivkinFull 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
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now