选择用于存储复杂动态用户配置文件/设置的模型
这是布局:
- 我正在使用 SQL Server 数据库开发一个内部 ASP.NET Web 应用程序(在 VB.NET 中)。
- 由于我的用户严格属于内部用户,因此我使用“Windows”方法进行自动身份验证。
- 我有四个用户角色,每个角色都有自己非常独特且动态的设置集。
- 奖励:每个用户可能有多个角色,因此有多个配置文件。
根据我的广泛研究,我确定了以下两种方法来存储用户配置文件设置(这两种方法都提示了问题“如何?”),尽管我不确定哪个是最好的(如果有的话):
- 在数据库中存储配置文件和相关设置(使用什么结构?从初步映射中,我至少创建了四张桌子开始变得很糟糕无法管理和维护)
- 使用内置的 ASP.NET 成员资格和配置文件对象? (我似乎找不到关于此的好的教程。这个方法仍然需要数据库支持吗?同样,使用什么表结构?) -我对这个可能的解决方案最感兴趣
示例:
我的最复杂的用户组需要能够存储与该用户关联的所有(用户选择的)产品的配置文件。假设我是一名产品经理,我希望我的帐户向我显示我选择负责的所有产品。显然,我的角色的每个成员都会有不同的产品和不同的数量等。也许用户页面设置(例如搜索、排序、订单默认值等)可以存储在通用表中,其中对奇怪内容的辅助设置表的引用,可以通过可以充当某种“外键”的特殊记录链接到该表。
根据要求,一个我对表格计划的想法:
Users (ID, Username, RoleID)
Roles (ID, RoleName, Description) --Lookup Table
Settings (ID, Name, Value)
UserSettings (ID, UserID, SettingID) --Junction Table
然后出现问题:
- 我什么时候应该使用行还是列?
- 如果我在每个设置中使用一列,我可以定义数据类型,但列数可能会失控。另一方面,如果我每个设置使用一行,则更有意义,但我失去了对设置的数据类型的控制。
- 我是否应该省略 UserSettings 表,而只使用 UserID 外键为 Settings 表中的每个设置附加一个名称=值对记录?
- 等等...
我的理想答案:
如你所见,我有很多问题,但似乎没有找到什么帮助。如果有人能用简单的术语为我解释它,我会喜欢它。请告诉我您的专业建议和一些关于如何实现它的超级简单的技巧(即使用哪些 ASP.NET 对象,以及所述对象如何提供机制管理我复杂的个人资料)
Here's the layout:
- I'm developing an internal ASP.NET Web App (in VB.NET) with an SQL Server Database.
- Since my users are strictly internal, I'm using the "Windows" method for automatic authentication.
- I have four user Roles, each with their own very unique, and dynamic, set of settings.
- BONUS: Each user may have multiple Roles and hence multiple Profiles.
From my extensive research I have determined the following two methods for storing user profile settings (both of which prompting the question "HOW?"), though I'm not sure which is best (if any):
- Store profiles and associated settings in the DB (Using what structure? From preliminary mapping, I've created at least four tables which is starting to get grossly unmanageable and unmaintainable)
- Use the built-in ASP.NET Membership & Profile object? (I can't seem to find a good tutorial on this. Does this method still require DB support? Again, using what table structure?) -I'm most interested in this possible solution
Example:
My most complex user group requires the ability to store a profile of all (user-selected) products associated with the user. Say I'm a product manager and I want my account to show me all the products that I've selected for which I am responsible. Obviously each member of my role would have different products and a different quantity of them, etc. Perhaps user page settings (e.g. search, sortation, order defaults, etc) could be stored in a generic table, with a reference to an auxillary settings table for the weird stuff which can be linked to through a special record which could act as a "foreign key" of sorts.
As Requested, one of my ideas for a table plan:
Users (ID, Username, RoleID)
Roles (ID, RoleName, Description) --Lookup Table
Settings (ID, Name, Value)
UserSettings (ID, UserID, SettingID) --Junction Table
Then the questions arise:
- When should I use a row vs a column?
- If I use a column per setting I can define datatypes, but column count could get out of control. On the other hand if I use a row per setting it makes much better sense, but I lose control over the data type for the setting.
- Should I omit the UserSettings table and just append a name=value pair record for each setting in the Settings table with a UserID foreign key instead?
- etc etc...
My Ideal Answer:
As you can see I have many questions and have found seemingly little help. I would LOVE it if someone could break it down for me in simple terms. Please tell me your professional recommendations and some super simple tips on how to implement it (i.e. which ASP.NET objects to use, as well as how said objects provide the mechanism for managing my complex profiles)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这几乎肯定需要在数据库中建模。
与用户相关的产品实际上并不是基于角色的东西 - 因此必须在很大程度上独立于角色,即使您说只有经理才会有这种关系。只有角色中的用户才会具有该链接,但这是您可以在应用程序级别或某些更高级别的约束上强制执行的高级限制 - 不使用外键 - 除非您具有依赖于用户和角色的链接。
那么充当经理的用户可能拥有某些产品,但充当推销员的用户可能拥有不同的产品。那么该角色也将在链接表中。有时,链接表行确实具有有关链接的属性,而不仅仅是链接本身(通常是有效日期和活动/禁用标志等)。
I think this almost certainly needs to be modeled in the database.
The products associated with a user would not really be a role-based thing - so would have to be largely independent of the role even though you say only managers would have that relationship. Only users in a role would have that linkage, but that's kind of a high-level restriction you might enforce at the application level or some higher level constraint - not with a foreign key - unless you had a linkage which depended upon user and role.
Then a user acting as manager might have certain products, but acting as a salesman, different products. Then the role would be in the link table as well. Sometimes link table rows do have attributes about the linkage, not just the linkage themselves (usually things like effective dates and active/disabled flags).