Fermin
Fermin

Reputation: 36111

LINQ2SQL: If I make changes to DB, how to mirror them in DBML?

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).

Upvotes: 3

Views: 341

Answers (4)

Michael Maddox
Michael Maddox

Reputation: 12489

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

Upvotes: -1

Funka
Funka

Reputation: 4278

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!

Upvotes: 2

spender
spender

Reputation: 120508

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.

Upvotes: 0

marc_s
marc_s

Reputation: 755197

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

Upvotes: 4

Related Questions