Friday, 13 September 2013

linq to sql concatenate - FirstName and LastName for a ListBox

linq to sql concatenate - FirstName and LastName for a ListBox

I'm trying to get the following to work. I have a table with the Fields
FirstName, LastName and DoctorId. I would like to populate a .net ListBox
using Linq to SQL. Here's what I have found and borrowed:
In a class I've called DALClass:
public List<Doctor> GetListDoctorsNames() {
using (var db = new WaitListDataContext())
{
return (from c in db.Doctors
select new
{
FullName = c.FirstName + " " + c.LastName,
DoctorId = c.DoctorId
}
).ToList<Doctor>;
}
}
The error has to do with the ").ToList;" line. The error is:
Error 1 Cannot convert method group 'ToList' to non-delegate type
'System.Collections.Generic.List'. Did you intend to invoke the method?
Q:\myapp\WaitList\App_Code\DALClass.cs 37 16 Q:\myapp\WaitList\
I'm not sure if I'm supposed to put instead of . I have tried that and it
doesn't work.

No comments:

Post a Comment