发布实体框架$ C $在启动项目没有上下文的C-首先迁移 [英] Publish Entity-Framework Code-First Migrations with no Context in the startup project
问题描述
我建立具有以下项目的解决方案:
I am building a solution with the following Projects:
-
Main.Data code> - 类库项目
-
Main.API
- Asp.NET MVC的WebAPI - 引用Main.Data li> -
主
- Asp.NET MVC 4 Web应用程序 - 引用Main.API
Main.Data
- Class Library projectMain.API
- Asp.NET MVC WebApi - references Main.DataMain
- Asp.NET MVC 4 web application - references Main.API
我有一个 MyContext:位于的DbContext
Main.Data code>项目中
类。
我也成功地发出有关 Main.Data code>项目
启用的迁移
控制台命令,我成功地使用的LocalDB作为SQL服务器,我的数据和升级数据库
迁移。
I have a MyContext : DbContext
class located inside Main.Data
project.
I have also successfully issues enable-migrations
console 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 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:
- 在
主/ Web.config中
我改变了连接字符串上下文类的FQN的名称:Main.Data.MyContext
。 - 添加从
主要参考
项目Main.Data code>项目(这是没有必要到现在为止)。
- Inside
Main/Web.config
I changed the name of the connection string to the FQN of the context class:Main.Data.MyContext
. - Add a reference from
Main
project toMain.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屋!