Linq to SQL,仅返回特定角色的用户
我正在使用 linq to SQL 以及 asp.net 会员资格提供程序。我设置了三个角色,但只想获取特定角色的用户。这是我返回所有用户的查询
public IQueryable<aspnet_User> GetAllMembers()
{
return db.aspnet_Users.OrderByDescending(u => u.UserName);
}
有人能指出我正确的方向吗?
谢谢
I'm using linq to SQL along with asp.net membership provider. I have three roles set up but want to get only the users of a particular role. This is my query to return all users
public IQueryable<aspnet_User> GetAllMembers()
{
return db.aspnet_Users.OrderByDescending(u => u.UserName);
}
Can anyone point me in the right direction?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来您需要讨论的内容 这里。 Tvanfosson 未经测试的答案得到了最多的支持:
根据提出问题的人(约翰)的说法,这对他来说不太有用,所以他最终这样做了:
希望这两个中的一个能够工作(请让我们知道哪一个适用于你)。
It looks like you need the same thing that was discussed here. Tvanfosson's untested answer was the most upvoted:
According to the person who asked the question (John) this didn't quite work for him so he ended up doing this instead:
Hopefully one of those two will work (please let us know which works for you).
为什么不使用会员资格提供程序附带的内置功能?
看看这里...
why not use the built in functions that come along with the membership provider?
Have a look here...
另一种选择是分两步执行此操作:
aspnet_UsersInRole
表查找您角色中的用户列表,aspnet_Users
表中筛选出以下用户:在该列表中类似这样的内容:
当然,在您的具体示例中,带有连接的直接方法之一将起作用 - 但有时这几乎难以表达,并且引入第二步可能最终会让事情变得更容易。您甚至可能希望根据其他一些标准进一步限制此用户列表,这可能无法通过联接轻松表达。
不管怎样,您一定能够找出这些用户! :-)
Another option is to do this operation in two steps:
aspnet_UsersInRole
tableaspnet_Users
table that are in that listSomething like:
Of course, here in your concrete example, one of the direct approaches with a join will work - but sometimes that's just almost too tricky to express, and introducing a second step might make things easier in the end. You might even want to further limit down this list of users based on some other criteria, that might not be easily expressible with a join.
One way or another - you'll definitely be able to figure out those users! :-)