开发者

Converting a "DBML" file to a "SQL database file"

I have the DBML file of a database and would like to generate an SQL database file fro开发者_如何转开发m this file.

Thanks


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


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.


You can use the CLI tool.

dbml2sql schema.dbml -o schema.sql

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜