C# Elmah DDL在通过context.Database.ExecuteSqlCommand(EF4.1)运行时给出sql错误

C# Elmah DDL在通过context.Database.ExecuteSqlCommand(EF4.1)运行时给出sql错误,c#,tsql,entity-framework,elmah,entity-framework-4.1,C#,Tsql,Entity Framework,Elmah,Entity Framework 4.1,我正在尝试在EF4.1 CodeFirst应用程序中生成数据库时运行Elmah Sql Server DDL 为此,在我的DbInitializer.Seed方法中,我有: protected override void Seed(MyJobLeadsDbContext context) { // Run Elmah scripts context.Database.ExecuteSqlCommand(GetElmahDDLSql); }

我正在尝试在EF4.1 CodeFirst应用程序中生成数据库时运行Elmah Sql Server DDL

为此,在我的
DbInitializer.Seed
方法中,我有:

    protected override void Seed(MyJobLeadsDbContext context)
    {
        // Run Elmah scripts
        context.Database.ExecuteSqlCommand(GetElmahDDLSql);
    }
getelmahdldlsql
只是一个字符串常量,它包含来自

不幸的是,在运行此操作时,我遇到以下异常:

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'GO'.
Incorrect syntax near the keyword 'ALTER'.
Incorrect syntax near the keyword 'ALTER'.
Incorrect syntax near 'GO'.
Incorrect syntax near the keyword 'SET'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Must declare the scalar variable "@ErrorId".
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Must declare the scalar variable "@TotalCount".
Must declare the scalar variable "@PageIndex".
Must declare the scalar variable "@TotalCount".
Must declare the scalar variable "@Application".
Must declare the scalar variable "@PageSize".
Must declare the scalar variable "@PageSize".
Must declare the scalar variable "@Application".
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Must declare the scalar variable "@ErrorId".
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.

知道如何通过EF4.1正确执行DDL吗?

我知道,您不能使用
GO
GO
不是SQL命令,它是SSMS中SQLCMD、OSQL或查询编辑器等工具的特殊批处理控制命令。使用ADO.NET或EF时,必须将SQL脚本划分为多个命令,并分别执行每个部分=两个GOs之间的每个部分都是单独的命令,需要自己的
ExecuteSqlCommand
。脚本中的全局变量可能存在一些问题

另一种方法是使用