0

asp.net identity framework autogenerates a string GUID as primary key in the AspNetUser table. How can i force the system to use an int instead?

Because according to this thread What are the best practices for using a GUID as a primary key, specifically regarding performance?, using GUID as primary key results in performance loss.

Community
  • 1
  • 1
Benjamin Martin
  • 576
  • 1
  • 8
  • 27
  • 3
    clustering key != primary key. I suggest re-reading the top answer again. How big is your application going to be? How many users do you expect to be using it? Avoid premature optimization. Get it working first, worry about performance when it rears it's ugly head (which it may never do). – user1666620 Oct 14 '15 at 14:58
  • 1
    Is your table going to contain so many users that performance is going to be an issue? – Bob Kaufman Oct 14 '15 at 14:59
  • Hi Bob, not yet but i think it could be :). – Benjamin Martin Oct 14 '15 at 15:03
  • @user: Yes but if i use the primary key as a foreign key, and then i want to select data, then isnt the system gona use it to order the records? – Benjamin Martin Oct 14 '15 at 15:04
  • 2
    @BenjaminMartin we all think "it could be". most of the time it isn't. The post you linked is talking about clustering keys, not primary keys. The accepted answer shows you how to achieve your aims. If you want to order your records, order by a datetime column, not by a sequential ID. Besides, why do you want to go messing around with the aspnetdb - it works fine as is. – user1666620 Oct 14 '15 at 15:04
  • ok thanks the website doesnt load fast. – Benjamin Martin Oct 14 '15 at 15:05
  • 1
    @BenjaminMartin I doubt the fact that your website "doesn't load fast" is because of the clustering index on the aspnetdb. I suggest you look at more obvious problems. – user1666620 Oct 14 '15 at 15:06
  • I mean this website, because i didnt hit the f5 key, sorry for my bad english – Benjamin Martin Oct 14 '15 at 15:07
  • 1
    While I agree with others that GUID's aren't necessarily a bad thing, Identity is actually set up to allow you change the key to whatever you like. As usual, try looking at the documentation: http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity – Chris Pratt Oct 14 '15 at 15:12
  • 2
    @BenjaminMartin, databases like Oracle, SQL Server, MySQL, etc., work really well right out of the box for most cases. Each has millions of programmer-hours behind it. For you to need to do an end run like this is something of a stretch. If you have performance issues with your app, there are plenty of other things you should be looking at before you start overriding the default behavior of the database. – Bob Kaufman Oct 14 '15 at 15:16

1 Answers1

1

You don't need to have a clustered index on the Primary Key. You can also find links that tell you to use GUID as primary key.

Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39