Is it always good practice to provide default values for integer-like fields? I use linq for database access.
Is it always good practice to provide default values for integer-like fields? I use
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume you are using linq-to-sql (even though the question is tagged only linq).
I would definitely advice against using default values in the db. The linq-to-sql layer (at least if generated with sqlmetal, I assume it is the same for the designer) will not use the default values from the database, but rather the default value for the C# type – which means
0for numeric types. In that case having default values which are not honored by the code will just cause confusion.