C
C#2d ago
Yasu

Can anyone help me switch my primary key column from int to uniqueidentifier for my web app?

so does anyone know how to switch from int to uniqueidentifier in my database and update my webapp so it generates uniqueidentifier keys instead of normal int
5 Replies
MODiX
MODiX2d ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, what you expect the result to be, what .NET version you are using and what platform/environment (if any) are relevant to your question. Upload code here https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code! (see $code for more information on how to paste your code)
Yasu
Yasu2d ago
there is no code atm
Angius
Angius2d ago
If there's no code, then... what do you want to switch?
Lamp
Lamp2d ago
assuming you're using efcore and .net8, I just make the type of the id property a guid then set new Guid() in the configuration file or something along those lines that's what i did for my app
Bailey
Bailey2d ago
Hello, before anyone can give a good answer, there is a lot of info needed. Just some pointers: - Is it a database which already is filled with records? - If there are any records, can they be removed - Is it an empty project ==> if Yes, you can delete the project and recreate with the correct id's. The sollution is dependant on the situation. If it's a relational database which is filled with data, there is (not necessarily) another sollution then if it's a new project. Just an example (of a possible sollution) if you got an existing relational database: 1) create the guid collumns (nillable) 2) fill the records with the related guids 3) add the foreign key 4) do checks by queries 5) remove the old foreign key and tables.
Want results from more Discord servers?
Add your server