I have a table of doctors in my database. So I'm trying to get the list of the firstName of the doctors in my database. In the ViewModel class I'm using this code to get it
public List DoctorsList ()
{
// string mainconn = Configuration
List ListOfDoctors;
using (var context = new GlabDbContext())
{
var result = (from c in context.Doctors
select c.LastName).ToList();
ListOfDoctors = result;
}
return ListOfDoctors;
}
I want to use this function like a method of my ViewModel class an it will have a return. But I'm getting an error saying that:
Impossible to convert implicitely 'System.Collections.Generic.List into 'System.Windows.Documents.List'?
I try to cast the result like this
public List DoctorsList ()
{
// string mainconn = Configuration
List ListOfDoctors;
using (var context = new GlabDbContext())
{
var result = (from c in context.Doctors
select c.LastName).ToList();
**ListOfDoctors = (list)result;**
}
return ListOfDoctors;
}
but I get an error at the run time for the app.
How can I resolve the problem?
Your
List ListOfDoctorsappears to be really anand this is also the return type of your method.
Your
var resultreally isThe two types are not compatible, meaning that you cannot cast one to the other (as the error message says).
I suspect you don't really want to return a
Documents.Listbut aList<string>(containing just those names). So:using System.Windows.Documents;from your fileListtoList<string>