我遇到同样的问题here,我已经尝试应用建议的解决方案,将连接字符串名称更改为放置在另一个项目中的数据库上下文的FQN。
Web项目Web.config文件(在项目MyApplication.Web中):
<connectionStrings>
<add name="FarmaciaNataliniServer.Infrastructure.ApplicationDbContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-FarmaciaNataliniServer-20151127115838.mdf;Initial Catalog=aspnet-FarmaciaNataliniServer-20151127115838;Integrated Security=True" providerName="System.Data.SqlClient" />
ApplicationDbContext.cs(在项目MyApplication中):
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<RegisteredDevice> RegisteredDevices { get; set; }
public DbSet<Reservation> Reservations { get; set; }
public ApplicationDbContext() : base("FarmaciaNataliniServer.Infrastructure.ApplicationDbContext", throwIfV1Schema: false)
{
}
...
不幸的是,这个解决方案似乎不再适用于Visual Studio 2015 :(
任何人都可以帮助我吗?
提前谢谢大家!
答案 0 :(得分:1)
我找到了解决问题的方法。我创建了一个新的项目,逐个添加文件和依赖项,我找到了哪些选项消失了。
他们是:
和一个从包PerpetuumSoft.Knockout继承KnockoutController的Controller。
我删除了这些依赖项,现在发布对话框中的Code-First选项可见并且可以再次激活。
不知道为什么这些依赖会导致这个问题,我没有看到任何相关性,但现在它正在按预期工作。 :)
答案 1 :(得分:0)
EF代码第一个工具(&gt; EF 6.X)运行良好,支持您的开箱即用的用例,允许开发人员通过将DB / EF与Web上下文/项目分离来遵循最佳实践。这真的是以正确的方式理解工具和做事的问题。我建议您设置一个新的解决方案,以尝试代码优先迁移。如果你没有以一种孤立的方式工作,不要在实际项目/解决方案中反复测试时丢掉你的时间。
在我们的项目中设置代码优先迁移时,我的团队得到了Microsoft员工的支持。他们做得对,我们在文档中保存了一些内容。
在浏览互联网时我发现这些页面很有用,我知道有很多帮助来处理EF代码优先开发和部署(特别是使用Visual Studio部署到Azure App服务)。
由于您的问题很难回答,我建议您遵循为EF 6.X和VS2015编写的最佳实践和文档,并回过头来更好地了解解决问题所需的工具。然后编辑你的问题或者只是问另一个问题。
为了给你一些开胃菜,只需看看migrate.exe的帮助 - 一个从命令行运行代码优先迁移的工具。有你可能需要的一切。
Uncaught Error: Syntax error, unrecognized expression: :nth-child
根据您传递给迁移工具的配置参数,您可以运行显式,基于配置文件或基于约定的迁移。密切关注正在打印的迁移是migrate.exe
Code First Migrations Command Line Utility
Applies any pending migrations to the database.
migrate assembly [configurationType] [contextAssembly] [/targetMigration]
[/startUpDirectory] [/startUpConfigurationFile]
[/startUpDataDirectory] [/connectionStringName]
[/connectionString] [/connectionProviderName] [/force] [/verbose]
[/?]
assembly Specifies the name of the assembly that
contains the migrations configuration type.
[configurationType] Specifies the name of the migrations
configuration type. If omitted, Code First
Migrations will attempt to locate a single
migrations configuration type in the specified
assembly.
[contextAssembly] Specifies the name of the assembly that
contains the DbContext type if different from
the assembly that contains the migrations
configuration type.
[/?] Display this help message.
[/connectionProviderName] Specifies the provider invariant name of the
connection string.
[/connectionString] Specifies the connection string to use. If
omitted, the context's default connection will
be used.
[/connectionStringName] Specifies the name of the connection string to
use from the specified configuration file. If
omitted, the context's default connection will
be used.
[/force] Indicates that automatic migrations which might
incur data loss should be allowed.
[/startUpConfigurationFile] Specifies the Web.config or App.config file of
your application.
[/startUpDataDirectory] Specifies the directory to use when resolving
connection strings containing the
|DataDirectory| substitution string.
[/startUpDirectory] Specifies the working directory of your
application.
[/targetMigration] Specifies the name of a particular migration to
update the database to. If omitted, the current
model will be used.
[/verbose] Indicates that the executing SQL and additional
diagnostic information should be output to the console window
<强> 1。显式参数
Origin
<强> 2。按配置文件
migrate.exe "Fireframework.Web.dll" "Fireframework.Web.Migrations.Configuration" /connectionString="Data Source=tcp:fireframeworkdbs.database.windows.net,1433;Initial Catalog=fireframeworkdbdev;User Id=ffdbadmin@fireframeworkdbs;Password="secret" /connectionProviderName="System.Data.SqlClient" /verbose
2016-04-25T08:06:09.9183260Z VERBOSE: Target database is: 'fireframeworkdbdev' (DataSource: tcp:fireframeworkdbs.database.windows.net,1433, Provider: System.Data.SqlClient, **Origin: Explicit**).
2016-04-25T08:06:13.5640428Z No pending explicit migrations.
第3。按惯例
migrate.exe "Fireframework.Web.dll" "Fireframework.Web.Migrations.Configuration" /startUpConfigurationFile="web.config" /verbose
VERBOSE: Target database is: 'fireframework' (DataSource: (LocalDb)\MSSQLLocalDB, Provider: System.Data.SqlClient, **Origin: Configuration**).
Applying explicit migrations: [201603161334138_InitialCreate, 201604081002396_Add_Simulation_CreatedDateTime_Property, 201604201138442_Add_Simulation_AbortRequestPending_Property, 201604211315107_Rename_Simulation_Properties].
Applying explicit migration: 201603161334138_InitialCreate.