public ActionResult myItems() {
var dataContext = new RecordsDataContext();
MembershipUser myObject = Membership.GetUser();
string CurrentUserName = myObject.UserName.ToString();
var u开发者_JAVA技巧ser = from i in dataContext.myUsers
where i.userName ==CurrentUserName
select i.id;
var items=from j in dataContext.OtherUsers
where j.id_user==user /*error:operator '==' cannot be aplied to operands of type 'int' and 'System.Linq.Iquerable<int>'*/
select j;
return View(items);
}
Please help me with this error
Actually user from the first query is not a single int result. You need to check if user.Count() is not 0 and you could use user.First() to retrieve first row result.
But I suggest to use join (something like that):
public ActionResult myItems() {
var dataContext = new RecordsDataContext();
var query = from i in dataContext.myItems
join ou in dataContext.OtherUsers
on i.id_user equals ou.id_user //check real reference, since I don't know
join mu in dataContext.myUsers
on ou.id_user equals mu.id_user
where mu.username == Membership.GetUser().UserName.ToString()
select i;
return View(query);
}
精彩评论