我试图在我的 EF4.1 CodeFirst 应用程序中生成数据库时运行 Elmah Sql Server DDL。
为此,在我的DbInitializer.Seed
方法中,我有:
protected override void Seed(MyJobLeadsDbContext context)
{
// Run Elmah scripts
context.Database.ExecuteSqlCommand(GetElmahDDLSql);
}
GetElmahDDLSql
只是一个字符串常量,包含来自http://code.google.com/p/elmah/source/browse/trunk/src/Elmah/SQLServer.sql的全部 DDL
不幸的是,当它运行时,我得到以下异常:
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 吗?