Is it possible to automatically create my Linq2Sql DBML via script?

I am using Linq2Sql and am tired of re-creating the dbml every time the database changes. Is it possible for a script to create my model, given that I want ALL tables and ALL processes? Ideally, this will be part of the build process or custom tool.

The simple "refresh from schema" button will be fine too, but from all that I can say there is no such thing. Currently, the only way to update my model is to delete tables and handles that have been modified and drag them from the server explorer.

Maybe something is missing for me?

+4
source share
3 answers

I suppose you can use the SQLMetal tool

EDIT OP: I ended up writing a batch file to check the code, generate classes with this, and then pass the code. Then I created a trigger for the database schema change level to run this batch file at any time when the schema changed. So now, when the schema changes, the Linq classes are created, checked, then CCNet creates the DLL and distributes it. sweet......

+4
source

If money is not an object, it is best to get the data modeling model of the 2008 Team System visual studio, create a database project and use it to support the database, data model and entity model. It's not a null job to keep the database and entity model synchronized, but using the schema comparison tool, it's not far from it (and it definitely does all the work for you).

IMHO, data modeling and roundtripping design more than justify the high cost of buying the Visual Studio 2008 team edition over the professional edition.

0
source

SQLMetal

http://msdn.microsoft.com/en-us/library/bb386987 (v ​​= vs .110) .aspx

The SqlMetal command-line tool generates code and mapping for the LINQ to SQL.NET Framework component. SqlMetal can perform several different actions, which include the following:

From the database, create source and display attributes or a mapping file.

From the database, create an intermediate database markup language (.dbml) for customization.

From the .dbml file, generate code and display attributes or file mapping.

This tool is automatically installed using Visual Studio.

SQLMetalPlus

A project in which .dbml can be auto-generated in Visual Studio using the refresh button.

http://www.codeproject.com/Articles/37198/SqlMetalPlus-A-VS-Add-in-to-Manage-Custom-Changes

SQLMetalPlus Forked on Github

Includes preinstalled installers.

https://github.com/thedemz/dotnet-sqlmetal-plus

0
source

All Articles