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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alex21
    New Member
    • Oct 2008
    • 19

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

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

    Code:
    public static Dictionary<string, Client> Clients = new Dictionary<string, Client>();
    Using this Linq query:
    Code:
    IEnumerable<Staff> loginquery = from staff in Database.Staff where staff.Value.Passcode == txt_password.Text select staff;
    but i get the error
    Code:
    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.
    Last edited by Frinavale; Jan 16 '09, 03:28 PM. Reason: Moved to C# from .NET
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    That's because your LINQ query isn't returning what you think it is. Try changing your LINQ query to

    var loginquery = ....

    instead.

    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...

    Comment

    Working...