0

Asp.net mvc 5 Identity 2.0 will create 5 tables automatically when run the mvc project.

Here, my question is why some tables like AspnetUser, it's item 'Id' type defined to string.

The String seems like GUID, but why it doesn't define to guid type instead of using string.

Is it transfer data type from string or do something when quering data ?

I can't figure out why it define to string, but look like guid ?

another table have same problem like AspnetRole, it's item 'UserId', 'RoleId' defined to string too.

Have any idea ?

2 Answers 2

1

I'm guessing this is having different reasons.

One reason is the insert performance for Guids, which will get slower and slower after an amount of data (Clustered indexes).

Another reason is the difference of handling Guid in different databases. Microsoft Sql Server has an UniqueIdentifier type that is a Guid, MySql will store them as strings, Oracle stores the raw bytes of a Guid...

I hope this explains a part of your queustion, as not fully :)...

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not 100% convincted, but a co-worker is, and I'm convinced by him. But that is definitely not the only reason as I said.
0

Identity framework not only created for code first approach to be generate database tables with given fields or datatypes. Identity framework can be used against existing database or migrate old asp.net membership provider, or we can use our own table names with extra database fields to store more data on identity tables.

Further more, the Id of the aspnetUser table (that is the User table) used as string because, we can use Guid, integer, long etc. for this field depending on the requirement.

E.g. : If you decided to use integer as Id of the aspnetUser table (User table), then the database field will be auto increment int (or bigInt or etc.) field. But you need to do model binding in order to fulfill entity framework migration requirements.

By default we get Guid inserted into this field when we use out of the box asp.net Identity framework.

When you have defined roles for the registered user, there will be record added into AspnetRole table, this is also completely depending on the fields we defined on the tables as I discussed before. If we decided to use integer as Id of the aspnetUser table, then AspnetRole table fields updated according to the relationship with aspnetUser table fields.

Hope this helps.

1 Comment

The key point of my question is why they use String by default ? I know that I can switch the type depending on my requirement, but why the system set String by default instead of GUID or Int ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.