queries in entity framework
hello i 开发者_如何学运维have tried the foollowing code and it is showing only assignment,call increment and new object expression can be uesd as a statement
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);
please give me the soluttion
If you expect multiple results from the query try this:
// 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;
If you need only the first result of the query you can try calling First()
right away:
Agentlist agent = res.First<Agentlist>();
精彩评论