6

I have the DBML file of a database and would like to generate an SQL database file from this file.

Thanks

3 Answers 3

3

You can use the CLI tool.

dbml2sql schema.dbml -o schema.sql

https://www.dbml.org/cli/#convert-a-dbml-file-to-sql

Sign up to request clarification or add additional context in comments.

1 Comment

The dbml2sql CLI tool can now be found at dbml.dbdiagram.io/cli
2

There's a method on the Data Context called CreateDatabase() that you could use.

http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.createdatabase.aspx

Comments

1

I know of no available utilities that do that, and it's a bit much to do for a SO answer.

But, for the most part, it's not that big a deal. The DBML file is written in XML; it should be easy to read via Linq-to-xml. Then just split out the SQL commands for the values in the xml into a script file. Then run the script. (It also could be done with a XSLT transformation)

<Table Name="dbo.Person" Member="Persons"> 

becomes

 CREATE TABLE Persons (

and

  <Column Name="PersonID" Type="System.Int32" DbType="Int NOT NULL IDENTITY"
          IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false">
  </Column>

  <Column Name="AddressID" Type="System.Int32" DbType="Int NOT NULL" 
          CanBeNull="false"></Column>  

becomes:

 PersonID Int NOT NULL,
 AddressID int NOT NULL,

and so on.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.