2012-08-23 63 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"