发布实体框架$ C $在启动项目没有上下文的C-首先迁移 [英] Publish Entity-Framework Code-First Migrations with no Context in the startup project

查看:124
本文介绍了发布实体框架$ C $在启动项目没有上下文的C-首先迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立具有以下项目的解决方案:

I am building a solution with the following Projects:


  • Main.Data - 类库项目

  • Main.API​​ - Asp.NET MVC的WebAPI - 引用Main.Data
  • - Asp.NET MVC 4 Web应用程序 - 引用Main.API​​

  • Main.Data - Class Library project
  • Main.API - Asp.NET MVC WebApi - references Main.Data
  • Main - Asp.NET MVC 4 web application - references Main.API

我有一个 MyContext:位于的DbContext Main.Data 项目中类。
我也成功地发出有关 Main.Data 项目启用的迁移控制台命令,我成功地使用的LocalDB作为SQL服务器,我的数据和升级数据库迁移。

I have a MyContext : DbContext class located inside Main.Data project. I have also successfully issues enable-migrationsconsole command on Main.Data project, and I am successfully using LocalDB as an SQL server for my data and for upgrade-database migrations.

问题开始时我正在尝试出版项目到Windows Azure网站。

The problem starts when I am trying to publish Main project to Windows Azure website.

发布正在使用从Windows Azure的网站导入自动创建个人资料似乎并不承认我使用实体框架code首先解决方案,并所以我不能让执行code首先迁移,我想。
相反,我只能启用更新数据库脚本。

The Publish Profile that is automatically created using Import from a Windows Azure web site does not seems to recognize that I am using Entity Framework Code First solution, and so I can't enable Execute Code First Migrations as I would like to.
Instead, I can only enable Update database scripts.

我使用Visual Studio 2012年实体框架5.0.0(自项目开始)。

I am using Visual Studio 2012 with Entity Framework 5.0.0 (Since the beginning of the project).

只是为了验证,我试图添加项目内部和<$临时 MyContext 类C $ C>启用的迁移项目,在那之后我的发布配置文件自动检测到实体框架code-第一。< BR>
也就是说,课程,没办法了(是吗?)

Just to verify, I have tried to add a temporary MyContext class inside the Main Project and to enable-migrations on the Main project, and after that my Publish Profile automatically detected Entity Framework Code-First.
That is, of-course, not a solution (or is it?)

下面是一些相关的主题:

Here are some relevant threads:


  • 是基础学习教程

  • 解释了部署选项,但没有排除故障。

  • This实际上给一些想法去尝试,但一切似乎不自然。

  • This is the base learning tutorial.
  • This explains deployment options, but no troubleshooting.
  • This actually gives a few ideas to try, but all seems unnatural.

我要寻找一个干净稳定的解决方案。我必须把我的Context类的主要项目中?

I am looking for a clean stable solution. Do I have to put my Context class inside the Main Project?

在此先感谢

推荐答案

我现在可以让执行code首先迁移当我创建一个发布配置。

这里是我做过什么来实现它:

I can now enable Execute Code First Migrations when I create a publish profile.
Here is what I did to achieve it:


  1. 主/ Web.config中我改变了连接字符串上下文类的FQN的名称: Main.Data.MyContext

  2. 添加从主要参考项目 Main.Data 项目(这是没有必要到现在为止)。

  1. Inside Main/Web.config I changed the name of the connection string to the FQN of the context class: Main.Data.MyContext.
  2. Add a reference from Main project to Main.Data Project (which was not needed until now).

这不工作对我来说。
如果有人得到了一个更好或更教育的答案,我会很高兴听到这个消息。

This does the job for me.
If anyone got a better or more educating answer, I would be happy to hear it.

这篇关于发布实体框架$ C $在启动项目没有上下文的C-首先迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆