在实体框架中查询

| 你好,我尝试了下面的代码,它只显示赋值,调用增量和新对象表达式可以作为语句使用
var res = from results in db.JobSearchAgents
where results.SiteID == 110 && results.UserID == sess
select new Agentlist
{
    JobSearchAgentID = results.JobSearchAgentID.ToString(),
    EmailAddress = results.EmailAddress,
    Keywords = results.Keywords,
    Country = results.Country,
    zipcode =  results.ZipCode,
    miles = results.Miles.ToString(),
    IsActive=results.IsActive.ToString()

};
string country= (new  ObservableCollection<Agentlist>(res))[0].Country);
请给我解决方案     
已邀请:
        如果您希望查询产生多个结果,请尝试以下操作:
// Calling ToList will force query execution.
List<Agentlist> result = res.ToList<Agentlist>();

// Calling First will take the first item in the collection.
// If there are more than one item it will NOT throw 
// an exception (calling Single() will).
Agentlist agent = result.First<Agentlist>();

string country = agent.Country;
如果仅需要查询的第一个结果,则可以尝试立即致电
First()
Agentlist agent = res.First<Agentlist>();
    

要回复问题请先登录注册