By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

C# Linq Query "Error 2 Cannot implicitly convert type"

P: 19
Ok i am trying to use a Linq query to access a dictionary.

Expand|Select|Wrap|Line Numbers
  1. public static Dictionary<string, Client> Clients = new Dictionary<string, Client>();
Using this Linq query:
Expand|Select|Wrap|Line Numbers
  1. IEnumerable<Staff> loginquery = from staff in Database.Staff where staff.Value.Passcode == txt_password.Text select staff;
but i get the error
Expand|Select|Wrap|Line Numbers
  1. Error    2    Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,Client_Care.Classes.DB_Classes.Staff>>' to 'System.Collections.Generic.IEnumerable<Client_Care.Classes.DB_Classes.Staff>'. An explicit conversion exists (are you missing a cast?)
Thanks for any help.
Dec 19 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 797
That's because your LINQ query isn't returning what you think it is. Try changing your LINQ query to

var loginquery = ....


It will still be safely typed. You will then be able to step through the code and see what the issue is using a watch on loginquery to evaluate its contents ;)

This will be more beneficial to you than me telling you directly what the problem is...
Dec 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.