简体   繁体   English

在Entity Framework迁移中更改数据库

[英]Alter database in Entity Framework migration

I want to enable broker for my database in an Entity Framework migration. 我想在实体框架迁移中为数据库启用代理。 I add a migration to my project and write this code in the Up method : 我将迁移添加到我的项目中,并在Up方法中编写以下代码:

Sql("ALTER DATABASE current SET ENABLE_BROKER", true);

This code runs correctly for SQL Server 2014, but when I change my target database to SQL Server 2008 R2 Express, I get this error: 此代码对于SQL Server 2014可以正确运行,但是当我将目标数据库更改为SQL Server 2008 R2 Express时,出现此错误:

Incorrect syntax near the keyword 'current' 关键字“ current”附近的语法不正确

How do I change the code to run properly for all type of SQL Server instances? 如何更改代码以在所有类型的SQL Server实例中正常运行?

Before SQL 2012 you have to use the database name. 在SQL 2012之前,您必须使用数据库名称。 Something like this batch: 像这样的批处理:

declare @sql nvarchar(max) = N'ALTER DATABASE ['+db_name()+N'] SET ENABLE_BROKER;'
exec( @sql );

should work. 应该管用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM