Carmax
Carmax

Reputation: 2917

Any drawbacks to using a string ID field in an mvc model?

We're creating a relatively basic CMS site in mvc4.

In the past we've always followed the convention of having auto generated int for the ID field, and having a separate string field to hold the url.

But most of the data retrieval is based on the url field.

Therefore, I'm wondering if it would be better to discard the int ID altogether and use the url field as the ID instead.

It feels like the right thing to do, but I'm worried it might cause me grief later on.

Other than making sure that each url is unique, are there any other implications or inconveniences this might cause me further down the line?

Upvotes: 0

Views: 55

Answers (1)

JaCraig
JaCraig

Reputation: 1078

Do you do a lot of joins on this field with other tables? If so, you'll need to store it as a foreign key multiple places and that would take up a bit of space potentially (but space isn't too big of a deal in today's computing world). Do you allow the user to update the URL? If so you'll have to also update the locations where it's the foreign key. That could potentially be slow depending on the database. Compares with varchar are slower than int usually so queries might be slower... I'd just index the URL and keep the surrogate key, but I tend towards the lazy side of things.

Upvotes: 1

Related Questions