如何在我的应用程序中使用的SELECT语句必须返回多个记录,以示对某一领域多个值(M:M的关系) [英] How to use in my application a SELECT statement that must return more than one record to show multiple values for a certain field (m:m relation)
问题描述
我不知道,如果你得到了我的意思,但我会尽力举个例子来说吧。
I don't know if you got what I mean, but I'll try to explain it with an example.
用户表
UsedId UserName
-------- ----------
1 Mike
2 Raul
HasPrivileges表
HasPrivileges Table
UsedId PrivilegeId
-------- --------------
1 1
1 2
1 3
2 2
2 3
权限表
PrivilegeId Privilege
------------- ------------
1 Create
2 Edit
3 Delete
现在这两个表的用户和权限,有它们之间的许多一对多的关系,所以当我选择所有他们所具有的权限相关联的用户,我得到了在这方面的例子3的记录或行的结果麦克每一个包含他有一个特权。
now this is two tables users and privileges that has a many-to-many relation between them, so when I select all the users associated with the privileges they have, I get the in this examples 3 records or rows in result for Mike each one contains a privilege he has.
现在我需要在我的应用程序,以显示所有用户与他们的特权的列表,但事实上,我不希望我的用户查看用户的三倍,以显示他的所有权限,或其他任何东西,而不是我希望它显示
Now I need in my application to display a list of all the users with their privileges but INDEED i don't want my users to see a user three times to show all of his privileges or anything else instead I want it to display
User Id : 1
Name : Mike
Privileges : Create, Edit, Delete
或东西接近这个!任何想法家伙!??
or something close to this! ANY IDEAS GUYS !??
推荐答案
您有ASP.NET和你的标签C#。考虑到你打算做什么是presentational问题,做到这一点在presentation层(即用C#)在数据层,而不是(即带有SQL)。这是一个容易得多了。
You have ASP.NET and C# in your tags. Considering that what you intend to do is a presentational issue, do it in the presentation layer (i.e. with C#) and not in the data layer (i.e. with SQL). That's a lot easier, too.
例如,这里所示:<一href="http://stackoverflow.com/questions/614542/use-linq-to-concatenate-multiple-rows-into-single-row-csv-property">Use LINQ来连接多个行成单行(CSV属性)
这篇关于如何在我的应用程序中使用的SELECT语句必须返回多个记录,以示对某一领域多个值(M:M的关系)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!