Visual Studio DBML and SQL column default value

Usually when creating a database table, you will tend to add “default values” to some columns (Guid, Dates, …).

ALTER TABLE [dbo].[User] ADD DEFAULT (getdate()) FOR [Created]

Adding the table to a DBML file under visual studio will ‘by default’ disallow the default value in the table.

The mapping with default values will work on identity and computed columns. It does not bring in default values set up in the database. You need to manually add those to your dbml table definitions.

Do not forget to set the value to True when you “delete” and re “add” the table into the dbml file.

3 Comments on “Visual Studio DBML and SQL column default value

    1. Mike says:

      Thanks for asking.

      Unfortunately, you can’t set a default value using the DBML.

      The only solution is to set the default value in the DATABASE, which is the BEST place (Performance, centralization, …) to do it.
      If you do not have access to the database, you could set the value when creating the corresponding table object.
      Lets give a example with my table user and setting a default value for “LG” to ‘EN’:

      User myUser = new User();
      myUser.LG = “EN”;


Leave a Reply