[英]how would I write linq query that would display user name instead of userID in a gridview
how would I write linq query that would display user name instead of userID in a gridview. 我将如何编写在网格视图中显示用户名而不是用户ID的linq查询。
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. 我正在寻找的是在Webiste中登录时仅看到他们提交的问题。
Bind only those columns needed to display the result. 仅绑定显示结果所需的那些列。 Turn off the
AutoGeneratedColumns
and add BoundField
columns. 关闭
AutoGeneratedColumns
并添加BoundField
列。
There are couple of issues with your query: 您的查询有几个问题:
where c.id == a.userId
) does not make sense. where c.id == a.userId
)没有意义。 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. 这将给您带来所有问题以及用户名-将网格列与
"name"
列绑定。
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. 如果要列出仅登录用户的问题,则必须添加where部分,例如
where u.user_id = currentUserId
,其中currentUserId
变量将保存登录用户的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.