Reputation: 1889
I have the DBML file of a database and would like to generate an SQL database file from this file.
Thanks
Upvotes: 6
Views: 7902
Reputation: 303
You can use the CLI tool.
dbml2sql schema.dbml -o schema.sql
https://www.dbml.org/cli/#convert-a-dbml-file-to-sql
Upvotes: 3
Reputation: 1943
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
Upvotes: 2
Reputation: 103485
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.
Upvotes: 1