As we do update our application, there is no doubt that we also need to make some changes on our database structure. What if we already set-up the LINQ to SQL Classes, how will you keep these two (SQL Database and LINQ Layout Diagram) sync together?
Unfortunately, updating the database structure from the SQL Management Studio doesn't guarantee that your project's LINQ Layout Diagram will update too. These two are separate entity that you need to do a little work to keep them in sync together.
Here are some ways:
1.
From the Visual Studio - delete, drag and drop.
a. On the Visual Studio, open the LINQ Layout Diagram, this is the file with the .dbml extension.
b. Select the table that you want to update, then delete by doing right click then "delete" or you can simply click the delete key on your keyboard.
c. Open the Server Explorer, select the table you want to update then drag to the LINQ Layout Diagram.
d. Notice that fields are now updated and the relationship are keep in place.
2.
Make the change directly in the properties - works on simple changes per field.
a. On the Visual Studio, open the LINQ Layout Diagram, this is the file with the .dbml extension.
b. Update the field
1. Select the field that you want to change and open the Properties pane.
2. On the Properties pane, make the necessary changes you want. Example, if you want to change the size of it's data type as NVarChar type from 50 to 200, do so by replacing the NVarChar(50) to NVarChar(200) under the "Server Data Type".
c. Add field
1. Right click on the table where you want to add field then select "Add" -> "Property".
2. Notice that new field is added, you can now set-up of the properties of that new item.
d. Delete field
1. You can simply delete a property by doing right click "Delete" on the property you want to delete or you can simply click the delete key on your keyboard.
3.
You can use a Third Party Software that does the auto sync.
Examples is the
Perpetuum Software and the likes.
L.