Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to Entities does not recognize the method 'System.String get_Item(System.String)' method

I've looked at the various solutions here but none of them seem to work for me, probably because I'm too new to all this and am groping in the dark a bit. In the code below, the object "appointment" contains some basic LDAP information. From a list of such objects I want to be able to get a single record, based on employee id. I hope the code here is sufficient to illustrate. FTR, I've tried various formulations, including trying to use from and a select. All fail with the error given in the Title above.

IQueryable<appointment> query = null;

foreach(var record in results)
{
    BoiseStateLdapDataObject record1 = record;
    query = db.appointments.Where(x => x.student_id == record1.Values["employeeid"]);
}

if (query != null)
{
    var selectedRecord = query.SingleOrDefault();
}
like image 512
user2283231 Avatar asked Apr 15 '13 15:04

user2283231


1 Answers

Try to move employee id getting out of query:

IQueryable<appointment> query = null;

foreach(var record in results)
{
    var employeeId = record.Values["employeeid"];
    query = db.appointments.Where(x => x.student_id == employeeId);
}

if (query != null)
{
    var selectedRecord = query.SingleOrDefault();
}
like image 178
Sergey Berezovskiy Avatar answered Nov 21 '22 02:11

Sergey Berezovskiy