Entity Framework 4.1 Code First not creating tables

后端 未结 4 968
予麋鹿
予麋鹿 2020-12-08 23:37

I am using EF 4.1 and have created a repository using DBContext etc. Connection string set to point to a SQL Server 2008 R2 Dev edition.

When I run a console app th

4条回答
  •  [愿得一人]
    2020-12-09 00:13

    You can create the tables yourself - the easiest way is:

    IObjectContextAdapter adapter = (IObjectContextAdapter)context;
    string script = adapter.ObjectContext.CreateDatabaseScript();
    context.Database.ExecuteSqlCommand(script);
    

    Where context is my EF 4.1 database context. Prior to this code I drop all the tables (from the last time I created the db), and after this I seed it with data.

提交回复
热议问题