如何使用API​​的成员与自己的应用程序相关的数据结合起来? [英] How to combine using Membership API with own application related data?

查看:130
本文介绍了如何使用API​​的成员与自己的应用程序相关的数据结合起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计4 asp.net一个新的应用程序,我必须做出决定如何使用MS SQL API成员与在MS SQL数据库我自己的数据一起。首先,我需要存储和访问用户配置文件方式更为灵活的数据则配置文件提供支持。其次我想链接的其他用户的相关信息(如订单)。

Designing a new application in asp.net 4 I have to make a decision how to use a MS SQL Membership API along with my own data in the MS SQL data base. Firstly I need to store and access user profile data in more flexible manner then the Profile provider supports. Secondly I would like to link other user related information (e.g. Orders).

无论你在哪里存储您的ASPNETDB表(在单独的数据库或与您的数据相同的数据的基础)的事情,问题就依然存在如何保持数据同步。

No matter where you store your aspnetdb tables (in the separate data base or in the same data base with your data), the problem stays how to keep your data synchronized.

在进行研究后,我看到下面的相关选项:结果
从asp_Users 1.外键用户ID(在本教程建议)。

2.无外键 - 使用交易(建议<一href=\"http://stackoverflow.com/questions/1938266/when-using-asp-net-membership-plus-an-additional-table-to-store-user-information\">here).

3.无外键 - 使用定制的AccountController(不管它是什么,建议<一href=\"http://stackoverflow.com/questions/1348173/how-would-you-use-entity-framework-1-0-with-asp-net-membership\">here).

4.它具有自定义用户ID(INT)链接会员用户ID(UID)附加表。结果
5. ...

After a research I see the following relevant options:
1. Foreign key UserId from asp_Users (suggested in this tutorial).
2. No foreign key - use transactions (suggested here).
3. No foreign key - use customized AccountController (whatever it is, suggested here).
4. Additional table which links Membership UserId (uid) with custom UserId (int).
5. ...

在一方面我喜欢的第一个解决方案,因为它是非常简单,建议在官方asp.net教程。

On the one hand I like the first solution as it is quite straightforward and is suggested in an official asp.net tutorial.

在另一方面对手注意到相当合理,使用外键打破,这是为了帮助分离关切,并可以互换供应商的总体思路。但遗憾的是他们没有去到很多执行细节,所以它不是很容易估算这些建议在相关性方面和实施的难易程度。

On the other hand opponents note quite reasonably that using foreign keys breaks the general idea of providers which are supposed to help separating concerns and to be interchangeable. But unfortunately they do not go much into implementation details so it is not really easy to estimate those suggestions in terms of relevance and ease of implementation.

那么,什么是接近这一目标的最佳选择吗?此外将如何实施样子?难道是足够使用只是额外的ADO.NET或LINQ等等code还是值得实现定制成员和/或配置文件提供?

So what is the best option to approach this? Furthermore how would the implementation look like? Would it be enough to use just additional ADO.NET or LINQ etc code or is it worth implementing a custom Membership and/or Profile Provider?

感谢您提前。

推荐答案

首先是simpliest方法。添加GUID的用户作为相关表(F.E. Ordered_by)一个ForeignKey的。我看不出它打破分离关注。如果你想保留在数据库中的订单纪录,你也必须保持谁已经订购了用户,这使得完美感。

The first is the simpliest approach. Add the GUID of the user as a foreignkey in the related tables (f.e. Ordered_by). I don't see where it breaks separating concerns. If you want to keep the order-record in database, you also have to keep the user who has ordered, that makes perfectly sense.

我在当前的应​​用程序使用的选项4成功。我创建了一个表格 aspnet_UserID ID用户INT 作为主键和fiUser(的GUID的 aspnet_Users )的外键。下面是模式:

I have used option 4 successfully in my current application. I've created a table aspnet_UserID with idUser int as primary-key and fiUser(the GUID of the aspnet_Users) as foreign-key. Here is the model:

(注:用户 aspnet_Users 表通过的 aspnet_regsql.exe的 aspnet_UserId 是我自定义的表每一个的Guid与我INT-ID)映射

(Note: User is the standard aspnet_Users table created via aspnet_regsql.exe and aspnet_UserId is my custom table that maps every Guid with my int-ID)

现在我存储只是我的 ID用户为FK所有相关的表格中(如在您的订单表)。有更少的存储和更具可读性的用户ID的(我永远记得GUID)的优势。也许这是稍微分开这个包装表,但不是我的主要意图。

Now i'm storing only my idUser as FK in all related tables (like in your Order-Table). That has the advantage of less storage and more readable UserID's(i could never remember a GUID). Maybe it's somewhat more separated with this "wrapper-table" but that was not my main intention.

您可以更改删除规则你foreignkeys 的,如果你想控制的行为。将其设置为梯级如果您F.E.要删除被你删除用户订购或将其设置为所有订单无操作如果你想保持这种秩序。

You can change the delete-rule on your foreignkeys if you want to control the behavior. Set it to Cascade if you f.e. want to delete all orders that were ordered by the user you're deleting or set it to no Action if you want to keep this order.

因为你没有提到你的意思,需要存储和访问用户配置文件方式更为灵活的数据则配置文件提供支持我可以不建议对档案问题的任何方案。

I can't suggest any alternatives for the Profile question because you haven't mentioned what you mean with "need to store and access user profile data in more flexible manner then the Profile provider supports".

这篇关于如何使用API​​的成员与自己的应用程序相关的数据结合起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆