how would I write linq query that would display user name instead of userID in a gridview.
var q = from u in entities.problems
join a in entities.my_aspnet_membership on u.user_id equals a.userId
join c in entities.my_aspnet_users on a.userId equals c.id
where c.id == a.userId
select new { u.problem_id, c.name, u.problem_description, u.problem_reported_datetime, u.problem_history};
What I am looking is when uasing login in the webiste only to see problems they submitted.
Bind only those columns needed to display the result. Turn off the AutoGeneratedColumns
and add BoundField
columns.
There are couple of issues with your query:
where c.id == a.userId
) does not make sense. For example,
var q = from u in entities.problems
join c in entities.my_aspnet_users on u.user_id equals c.id
select new {
u.problem_id, c.name, u.problem_description,
u.problem_reported_datetime, u.problem_history
};
This will give you all problems along with user name - bind the grid column with "name"
column.
If you want to list the problems for only logged in user then you have to add where part such as where u.user_id = currentUserId
where currentUserId
variable will hold the value of logged in user.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.