Created
April 24, 2016 23:07
-
-
Save maxkoryukov/3454b349a7619c77460f485b566850de to your computer and use it in GitHub Desktop.
Simple .dbml to .sql converter (XSLT)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet | |
version="2.0" | |
xmlns:dbml="http://schemas.microsoft.com/linqtosql/dbml/2007" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
> | |
<xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/> | |
<xsl:variable name="newline" select="'
'"/> | |
<xsl:template match="dbml:Database"> | |
<xsl:for-each select="dbml:Table"> | |
<xsl:text>CREATE TABLE </xsl:text> | |
<xsl:value-of select="@Name" /> | |
<xsl:text> (</xsl:text> | |
<xsl:value-of select="$newline"/> | |
<xsl:for-each select="dbml:Type/dbml:Column"> | |
<xsl:text> [</xsl:text> | |
<xsl:value-of select="@Name" /> | |
<xsl:text>] </xsl:text> | |
<xsl:value-of select="@DbType" /> | |
<xsl:if test="position()!=last()"> | |
<xsl:text>,</xsl:text> | |
<xsl:value-of select="$newline"/> | |
</xsl:if> | |
</xsl:for-each> | |
) | |
GO | |
ALTER TABLE <xsl:value-of select="@Name" /> | |
ADD CONSTRAINT PK_<xsl:value-of select="@Name" /> PRIMARY KEY ( | |
<xsl:for-each select="dbml:Type/dbml:Column"> | |
<xsl:if test="@IsPrimaryKey='true'"> | |
<xsl:value-of select="@Name" /> | |
</xsl:if> | |
</xsl:for-each> | |
) | |
GO | |
<xsl:value-of select="$newline"/> | |
</xsl:for-each> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment