views:

24

answers:

3

I have a small L2S database that was generated with the L2S CreateDatabase command. When I add a class or property to the DBML, the database is not updated automatically. I get errors like "Table not found" at runtime.

Is there a way to add new tables and columns to a database?

+1  A: 

No, LINQ to SQL cannot update your database schema to reflect changes made to DBML. To do so you'll have to either recreate your DB from scratch (which, granted, LINQ to SQL does not do very well), or use something like Wizardby to version and upgrade your DB schema.

Anton Gogolev
Thanks for confirming this.
Doug Clutter
A: 

No it is not. You need to refresh your Server Explorer, and then remove your changed table form DBML, then drag and drop it and CTRL + S :}

Serkan Hekimoglu
I'm not trying to update the DBML from the database...rather I'm trying to update the database AFTER the DBML has changed. Furthermore, I may not have access to the database. For instance, the customer creates the database by running version 1. I send out version 2 that has a new table. When the user runs version 2, they get a "Table not found" error because the new table isn't in their database. Does that clarify?
Doug Clutter
A: 

Not out of the box, but there are third party tools that add that kind of functionality. Take a look at my tools - Huagati DBML/EDMX Tools.

The add-in can generate the change scripts for you, and there is also a runtime component that can be used within your app to detect and generate SQL-DDL for diffs between the model and the database.

KristoferA - Huagati.com