1

I'm building an asp application from the ground up using Linq-to-SQL as my ORM. I have a dbml file with a datacontext that includes all the tables of the database (15 for now). If I make changes to the database, by adding a table, adding fields or by changing the data type of a field for instance, how are these kinds of change handled when they occur?

Do I simply drag and drop the new table on the ORM mapper and voila?

Thanks.

frenchie
  • 51,731
  • 109
  • 304
  • 510
  • See also: http://stackoverflow.com/questions/956131/when-i-make-a-database-change-how-do-i-know-what-needs-to-be-removed-and-readded – Michael Maddox Jan 11 '11 at 11:09

3 Answers3

1

Have a look at How to update Linq to SQL dbml file? [best practice] there you will find your answer.

Community
  • 1
  • 1
Mark
  • 3,273
  • 2
  • 36
  • 54
0

I prefer to use SqlMetal (via a bat file) to fully regenerate the DB schema.

However, you'll find that SqlMetal generates for the entire database. To remove certain tables or relationships; and/or to rename certain tables or generated properties you could look at my blog on filtering items generated by SqlMetal using Powershell.

However, you could of course do it all via the visual studio designer, but that's manual and annoying to repeat for a small change. Or you could manually deal with DBML but that is nasty.

Reddog
  • 15,219
  • 3
  • 51
  • 63
-1

The Visual Studio IDE transfer the changes you do to your dbml file to your ORM classes automatically.

  • even if I add fields to existing tables? – frenchie Jan 10 '11 at 23:19
  • It certainly doesn't do this in VS2008... Maybe in VS2010? – Reddog Jan 10 '11 at 23:31
  • VS doesn't update the classes automatically, but if you change the DBML file then yes the classes will be updated. However this doesn't answer the question - how should frenchie update the DBML file? – Kirk Broadhurst Jan 11 '11 at 00:04
  • @Kirk Broadhurst: You can edit the .dbml file using VS. Check this video: http://www.youtube.com/watch?v=xiemFC3Q7rg And, if you change the dbml, as in the video, the VS will do update classes. There is no automatic mapping between database and model. But, as frenchie said "Do I simply drag and drop the new table on the ORM mapper and voila?" - yes, simple drop to dbml and it will reflect on model – Tiago Deliberali Santos Jan 11 '11 at 01:21
  • No, if you drag a table onto the designer then a second reference will be created, `Table_1`. That's not what he wants. He can edit the DBML file directly, or *remove* and then *re-add* the table. Either works, both have drawbacks. – Kirk Broadhurst Jan 13 '11 at 21:48