2012-08-23 62 views
10

当每次需要添加迁移或更新数据库时使用EF 4.3.1迁移时,我必须使用StartUpProject参数。我可以设置这个地方,所以我不必继续这样做吗?我不想将我的数据项目设置为启动项目。如果情况有所改变,我的环境和迁移将处于不同的项目中。为实体框架迁移设置启动项目参数

不使用StartpProject参数时抛出异常:

update-database -verbose 
Using NuGet project 'Data.Deployment'. 
Using StartUp project ''. 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) 
    --- End of inner exception stack trace --- 
    at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) 
    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) 
    at System.Management.Automation.ComMethod.InvokeMethod(PSMethod method, Object[] arguments) 
Exception has been thrown by the target of an invocation. 

回答

2

我不知道如果这是你在说什么,但你可以在包管理器控制台设置默认项目到项目中,您的Migrations配置驻留在;它是最右边的下拉列表。
这样我就不必提供启动项目作为参数。

+0

我已经做到了,但如果我不指定ŧ他StartupProject参数引发异常 –

+0

认真?你能发布异常的整个输出吗? –

+0

在 –

1

一个简单的方法是将测试项目附加到解决方案。

即使您不想编写大量的单元测试,它也是适用于数据层名称空间或类似的启动项目。

这使得您的启动问题变得更加清晰,包管理器适用于整个解决方案IIRC - 因此请确保默认项目是包含其中的migrations文件夹的项目。

7

至少与实体框架6,指定启动项目使用-StartUpProjectName参数与更新的数据库:

update-database -StartUpProjectName <String> 

您可以使用软件包管理器控制台内的get-help命令来查看可能的参数命令:

get-help update-database -detailed 
0

使用StartupProject参数:Update-database -StartupProject "PROJECTNAME"