Is it good idea to use uint instead of int as the primary key in data model class?

前端 未结 4 1313
臣服心动
臣服心动 2020-12-18 18:45

We know that the primary keys are usually positive integers.

Is it good idea to use uint instead of int as the primary key in data model cl

相关标签:
4条回答
  • 2020-12-18 19:06

    In case somebody else stumbles on this question - don't use uint for your keys. I've just tried that with Entity Framework 6.1.12 and code kept failing with cryptic "Entity doesn't have key" exception.

    Only after I've changed uint property back to int it started working as expected.

    So, yeah, it sucks to have 2+ billion range unused, but that's how things are. And if you have even a slight doubt that you may end up with billion plus records, go with long. Ironically, then you'll have 9,223,372,036,854,775,808 numbers unused ;).

    0 讨论(0)
  • 2020-12-18 19:14

    uint is not CLS compliant, so it's generally recommended not to use it in public APIs.

    0 讨论(0)
  • 2020-12-18 19:22

    The corresponding SQL data type is a signed number, so I'd stick with the int to avoid any surprises.

    0 讨论(0)
  • 2020-12-18 19:22

    I think it's bad idea, cause of int type is more optimized for using in .NET Framework.

    0 讨论(0)
提交回复
热议问题