Reputation: 339
My code did work but now it is telling me I have an explicit conversion in my return line.
public IEnumerable<Contacts> GetAllContacts()
{
var Contacts = from c in dbc.Contacts select c;
return (IEnumerable<Contact>)Contacts;
}
Upvotes: 0
Views: 2167
Reputation: 103555
You misunderstand the error message. It was actually (something like)
Unable to implicitly convert type
System.IEnumerable<Contact>
toSystem.IEnumerable<Contacts>
. An explicit conversion exists (are you missing a cast?).
Which means that you are trying to return an IEnumerable<Contact>
when the method signature says IEnumerable<Contacts>
(note the s
).
The compiler is saying that you could explicitly cast to IEnumerable<Contacts>
(a conversion exists) - not that you are explicitly converting.
So you need to change your cast to (IEnumerable<Contacts>)Contacts
, to match the method signature, and the result of your LINQ query.
Upvotes: 7