Ah, but the UserName field would only be unique within that table, not across databases. The purpose of using a GUID for the UserId is to ensure that the user's identifier will be unique outside of that table for multiple applications where that is necessary.
(For example, for security purposes, our client requires us to have separate databases for each of their clients for authentication and other uses, but these need to be unique across all of the client databases because all of their clients will access yet
another shared database that needs to track who accesses it.)
Ah, but the UserName field would only be unique within that table, not across databases. The purpose of using a GUID for the UserId is to ensure that the user's identifier will be unique outside of that table for multiple applications where that is necessary.
(For example, for security purposes, our client requires us to have separate databases for each of their clients for authentication and other uses, but these need to be unique across all of the client databases because all of their clients will access yet
another shared database that needs to track who accesses it.)
You might be able to contort it to achieve this, but if this is your requirement then I'd suggest that membersip is not the best framework given that the point of membership is to abstract away the database.
jazzyhacker
Member
11 Points
103 Posts
ASP.NET MVC 4 Simple Membership
Nov 05, 2012 11:36 PM|LINK
Is it possible to change the UserId datatype from int into uniqueidentifier? How to handle the generated value of that uniqueidentifier?
Thanks in advance.
CPrakash82
All-Star
18284 Points
2841 Posts
Re: ASP.NET MVC 4 Simple Membership
Nov 06, 2012 12:54 AM|LINK
I believe it can be done with binary 16 or char 32 could be 36. But you need to modify the code around to insert the GUID.
jazzyhacker
Member
11 Points
103 Posts
Re: ASP.NET MVC 4 Simple Membership
Nov 06, 2012 01:19 AM|LINK
I think we don't have to modify the code because SQL Server has capability to add the default value for uniqueidentifier like below:
CREATE TABLE Users( Id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(), UserName VARCHAR(255) ); INSERT INTO Users(UserName) VALUES('admin'); INSERT INTO Users(UserName) VALUES('user'); SELECT * FROM Users; ---------------------------------------------------------------------------------------------------------------------- Id UserName ================================================ E929813D-19E4-4AA9-8CF5-2A1D766500BA user 6F2D4437-E4A1-41ED-8B06-EAB897A9E9DB adminHow to do that in code first? Thanks in advance.
BrockAllen
All-Star
27530 Points
4905 Posts
MVP
Re: ASP.NET MVC 4 Simple Membership
Nov 06, 2012 12:44 PM|LINK
No, simple membership uses an int. The username should be unique anyway, so that's what you should treat as your unique id for the user.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
moresby
Member
7 Points
2 Posts
Re: ASP.NET MVC 4 Simple Membership
Nov 28, 2012 04:06 AM|LINK
Then why bother with the ID column at all ?
jazzyhacker
Member
11 Points
103 Posts
Re: ASP.NET MVC 4 Simple Membership
Nov 28, 2012 04:25 AM|LINK
bobquinn
Member
2 Points
1 Post
Re: ASP.NET MVC 4 Simple Membership
Feb 23, 2013 08:14 AM|LINK
Ah, but the UserName field would only be unique within that table, not across databases. The purpose of using a GUID for the UserId is to ensure that the user's identifier will be unique outside of that table for multiple applications where that is necessary. (For example, for security purposes, our client requires us to have separate databases for each of their clients for authentication and other uses, but these need to be unique across all of the client databases because all of their clients will access yet another shared database that needs to track who accesses it.)
BrockAllen
All-Star
27530 Points
4905 Posts
MVP
Re: ASP.NET MVC 4 Simple Membership
Feb 23, 2013 12:59 PM|LINK
You might be able to contort it to achieve this, but if this is your requirement then I'd suggest that membersip is not the best framework given that the point of membership is to abstract away the database.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/