Best way to change ASPNETUsers.Id to a GUID

hi guys,

i have been working away at configuring my DB for a project and i have set up default security on the project.

this has executed an EF migration to the database and set up the ASP NET user management tables.

i note on these tables that the ID field contians a GUID however the actual field type in the DB is a NVARCHAR(450)

i have no idea why this is set to NVARCHAR(450) instead of a UNIQUEIDENTIFIER but for all my table references where i have records which have a related "CreatdById" i.e. the user ID who created the record i simply want to do a FK relationship to the ASPNETUsers.ID field

so question... what's the best way to change the ID's in the ASPNET user management tables (all of them) to be a UNIQUEIDENTIFIER type to hold the GUID ?


Hi @TMRGlobal,

Not sure how your question is related to Radzen. Maybe Stack Overflow will be much better in this case.

the reason i raised this here is because there are possible UI implications of changing the underlying data type for user management,

i don't know why the ASPNET user EF migration didn't simply apply a uniqueidentifer as the userid through those tables, but changing the DB would likely result in a code problem for adding users, updating users, etc.

there is a flow through implication is my line of thought.

so with the aim to simply swap the NVARCHAR(450) to a UNIQUEIDENTIFIER at the database level i would like to know of the best approach which will not put existing code for user management, etc at risk in Razden.

does that make sense?


I have been giving this some thought, specifically how to solve without code....

one approach i came up with is to add a new column to the ASPNETUsers table and call it UserId
set the type to UniqueIdentifier and then default value to newid()

this would probably have the effect of getting a unique ID onto the table which can easily be linked through the rest of the database with FK relationships.

this would also not impact the "get current user" functions already in Razden or the "create user", etc... functions.

where this is likely to break down is when i am saying on my "add XXXX page" is i want to link the current logged in user to the record. so if i use the out of the box Razden function for that it will work against the current ID which is NVARCHAR(450)

so at minimum i think this approach would require an additional function such as getCurrentUser_UserId()

or something like that which would return the DB generated GUID......

the only other alternative i can think of is to either change the DB and re-run the data sync... see what happens and then fix it....

update the models, etc and execute another EF migration..... again run it and see what happens....

are there any other thoughts or a proven approach to changing the ASPNETUsers.ID value from NVARCHAR(450) to a UniqueIdentifier (GUID) ???


I believe this is covered by the official Microsoft documentation.

yeah i was hoping to not have to do that :slight_smile:
thanks @korchev i'll have a play with it and see where i land