views:

51

answers:

4

I am new to LINQ. I am using Visual Studio 2008 and have created a "LINQ to SQL Classes" (.dbml) file in my project. I've added each of my database tables to the design view and everything works fine.

My question is this: When a change to a table's design has been made in the database, i.e. fields added, how do you update the classes to reflect the changes? Do you have to delete the table from the dbml design view and drag it back onto the design view surface each time a table gets changed? It seems like there should be a better way, or that the table classes should dynamically update themselves with new fields added/removed. The table classes do not seem to notice/update/refresh the table changes on their own.

Thanks in advance for any advice you can offer!

A: 

Yes. You must either manipulate the .dbml xml file or delete the table and re-add.

Typically, I keep my modifications to a minumum so that I can just delete all the tables and add them all back in to maintain relations etc.

PIA is an understatement.

p.s. there is no better way. (that I know of)

Sky Sanders
Thank you Poet, that's not the greatest news, but thanks. I'll wait to see if anyone else has a clever idea before marking as answer.
Blue Steel
+1  A: 

There are a number of ways to deal with that. The built-in way is to edit manually, or to remove the affected tables from the diagram and re-add them, or to re-generate the entire DBML file with the designer or with SQLMetal. The drawback is that any customizations (changed class/property names etc) you may have done need to be re-done every time.

Alternatively, there are third-party add-ons that provide sync functionality. My company makes one of those tools, you can read more about it, download, and get a trial license at http://www.huagati.com/dbmltools/

KristoferA - Huagati.com
+1  A: 

It is not necessary to delete and re-add the table. You can manually add or remove fields in each table in your dbml. The tables on the dbml diagram are right-clickable. When adding a new field, you can use the property sheet to identify the data type and the column mapping back to the database.

If you're making significant changes, this can be tedious, and deleting and adding back the tables is usually simpler and quicker. But if you do any customization, such as adding relationships to the dbml that aren't present in the database, then when you delete and readd a table, you'll also need to recreate the relationship.

Lane
A: 

I use a T4 transformation for LINQ2SQL.

This allows me to simply drag and replace the entire massive and ugly DB schema on the design surface when when changes happen.

leppie