Usually when creating a database table, you will tend to add “default values” to some columns (Guid, Dates, …).
BEGIN ALTER TABLE [dbo].[User] ADD DEFAULT (getdate()) FOR [Created] END
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.
Hi
any idea on how to do that.
That is how to add a default value to a column of a particular table using the dbml.
Thanks
Hi,
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”;
Mike
Yes, I did set my default value in the database and then I followed the above steps and it worked
Thanks