2012-03-01 72 views
0

Today EF4.3.1 released. http://blogs.msdn.com/b/adonet/archive/2012/02/29/ef4-3-1-and-ef5-beta-1-available-on-nuget.aspx .How to Use migration with existing database?

Follow the blog: http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/ . I firstly run:add-migration initial but throw exception as below and no create folder migrations:

PM> add-migration initial System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.ArgumentException: 参数不正确。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG)) --- 内部异常堆栈跟踪的结尾 --- 在 System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) 在 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) 在 System.Management.Automation.ComMethod.InvokeMethod(PSMethod method, Object[] arguments) 调用的目标发生了异常。

thus, I run Enable-migrations firstly. the folder migrations with Configuration.cs created. I checked the database, under system tables without dbo._migrationhistory table. then I run add-migration initial again. throw the same exception Mentioned before.

the Domain model in a project and the datacontext in another project which locate in DAL layer.

in my existing database Security there are several table such as role ,user and so on. but no migration-history table.

there is only Iset Navigators in my datacontext. no match database tables. My problem is how to get migration-history table and set up migration?

+0

what exception do you see, the migration-history is a system database, you need expand the System Tables to see it. – 2012-03-01 15:35:45

+0

What exception did you get? – 2012-03-01 23:52:12

+0

I have Added the exception in the post. – Simon 2012-03-02 01:23:55

回答

0

I finally found that if move the project out of solution Folder. it will work fine. maybe it's a bug.