views:

135

answers:

4

Hi,

I am using LINQ2SQL in my current project. I have a quite a lot of tables ~30. When I create my DBML file I change some of the column names etc for readability.

Recently if I made a change to the table in the underlying Database I just deleted and re-added the table in the DBML file, but this is getting tedious. How can I mimic any changes to the database in the DBML file? (e.g. new column, drop column, new default constraint etc)

Thanks.

A: 

Welcome to the world of tedious! Unless I missed something, you're doing it the right way.

SubSonic looks like an interesting alternative, and boasts

It will also create your database on the fly if you want, altering the schema as you change your object.

spender
+3  A: 

Out of the box, Linq-to-SQL has no update feature - amazing, but unfortunately true.

There's two tools I know of that get around this:

  • PLINQO is a set of CodeSmith code generation templates which handle DBML generation and offer lots of extra features (like generating one file per db entity) - including updates!

  • The Huagati tools offer updates and enforcing naming conventions for DBML and Entity Framework

Marc

marc_s
+1  A: 

I'm not expecting this to be the correct answer, but I thought I'd chime in anyway.

My approach has been to use the drag-n-drop feature for creating the initial DBML file. Then, any changes I make in my DB are also then made, by hand, in either the designer or in the DBML file (as XML) itself. (You can right-click on the DBML file, select Open With, and choose XML editor.) Sometimes it is much easier/faster to work with its XML instead of messing around in the designer.

I would only consider the deleting and re-adding, as you have been doing, if the changes were significant. For adding a new column, however, I'd suggest working directly with the dbml's XML, it's probably faster.

Good luck!

Funka
oh yes, and marc_s does mention some nice alternatives to this (which is perhaps more along the lines of what you were seeking?) I'm just throwing out my "poor man's" solution for posterity/any commentary...
Funka
A: 

As far as free solutions, there are a couple of blunt instruments that mostly move you away from using the O/R Designer: SQLMetal and Damien Guard's T4 templates.

There are multiple commercial solutions available that offer a lot more features.

The question you have to ask yourself is: Am I using the right ORM? LinqToSql has quite a few significant drawbacks, database change handling being only one of them.

Do not use the Visual Studio 2008 LinqToSql O/R Designer

The drawbacks of adopting Linq To Sql

Michael Maddox