问题:
So I have a table with an identity column as the primary key, so it is an integer.所以我有一个以标识列作为主键的表,所以它是一个整数。 So, why does SCOPE_IDENTITY()
always return a decimal value instead of an int to my C# application?那么,为什么SCOPE_IDENTITY()
总是向我的 C# 应用程序返回一个十进制值而不是一个 int 值? This is really annoying since decimal values will not implicitly convert to integers in C#, which means I now have to rewrite a bunch of stuff and have a lot of helper methods because I use SQL Server and Postgres, which Postgres does return an integer for the equivalent function..这真的很烦人,因为十进制值不会在 C# 中隐式转换为整数,这意味着我现在必须重写一堆东西并有很多帮助方法,因为我使用 SQL Server 和 Postgres,Postgres 确实为等效功能..
Why does SCOPE_IDENTITY()
not just return a plain integer?为什么SCOPE_IDENTITY()
不只是返回一个普通的整数? Are there people out there that commonly use decimal/non-identity values for primary keys?有没有人通常使用十进制/非身份值作为主键?