Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Membership - CreateUserWizard

Status
Not open for further replies.

wallm

Programmer
Apr 4, 2005
69
GB
I'm using the CreateUserWizard and the ASPNETDB.mdf database.
If I create a new database table I would like to create a relationship between the aspnet_Membership table and my new Orders table.
I'm not sure how to do this. Would I need to get the UserID for the newly created member and place that in the new table?

thanks.
 
The user ID is the primary key for the aspnet_Users table so you'd want to create a foreign key constraint from your Orders table to the aspnet_Users table.

From there, whenever a user places an order, you should be able to retrieve the key (which is a uniqueidentifier/GUID) thusly:

Guid userKey = (Guid)Membership.GetUser(User.Identity.Name).ProviderUserKey;

'Now insert a record in the Orders table using the key.
 
thanks for your help.
I've just been advised that membername is also unique.
 
Actually, UserId is the only value associated with a user that's guaranteed to be unique by database constraints. Concevably you can have multiple applications using the same membership database where the UserName field will be identical.

Additionally, there's no index associated with aspnet_Users.UserName so you may run into performance pitfalls with joins to that field unless you do a little manual index tuning.

There is, however, a clustered index on ApplicationId/LoweredUserName so you may want to look into that if you want to use LoweredUserName.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top