我正在尝试使用Dapper运行SQL查询:
use master
go
if exists (select name from sys.databases where name = N'TestDB')
drop database [TestDB]
go
create database [TestDB] on primary (
name = 'TestDB_Data',
filename = '$Path\TestDB_Data.mdf',
size = 40MB,
maxsize = 2GB,
filegrowth = 20MB
)
use [TestDB]
go
create table dbo.Posts
(
Id int identity not null,
Body nvarchar (max) null
);
我正在使用Dapper,如下所示:
using (SqlConnection connection = new SqlConnection(connectionString)) {
connection.Open();
connection.Execute(sqlQuery);
}
然而,当我使用GO语句时出错了。
但是,如果我删除GO语句,则在创建帖子时会出现错误,因为TestDB表尚未创建。
是否有一种使用Dapper来解决这个问题的方法?
我只能使用SQL Server SDK才能做到这一点。
GO
不是 T-SQL 语句,它只是由某些 SQL Server 实用程序解释的指令。http://msdn.microsoft.com/en-us/library/ms188037.aspx - Pero P.