Database Primary Key C# mapping - String or int

前端 未结 3 585
悲&欢浪女
悲&欢浪女 2021-01-15 05:25

In the Northwind Starters Kit, Primary keys from database are mapped to Strings in C#.

Is this good practice? And if so, why?

thx, Lieven Cardoen

ps:

3条回答
  •  既然无缘
    2021-01-15 05:57

    It all depends on the data type of the column in the database.

    Good practice is to use a compatible/corresponding data type. If the database uses int, use int. If the database uses uniqueidentifier, use Guid. If the database uses nvarchar, use string.

    Anything else will give problems down the line. Guaranteed.

提交回复
热议问题