I have a data model that I created using the EF codefirst approach. First, I created the model classes in my Mod folder of My application and created my database from it, working perfectly. But now I want to add another project to my solution that uses the same model (database), so I created a class library project (BM.Core) and put my models, context class and repository in this project and created another library project classes (BM.Services) and put in it all the service classes that access the repository classes and models inside it.
Then I deleted my database from SSMS, then turned on migration in my new Model project, BM.Core, and created the database. But when I access the context in my repository class, I get the following error
Context cannot be used during model creation. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads simultaneously
so I searched google about this error and I got a solution from this: post
and i put
ctx.Database.Initialize(force: false);
in my repository designer while the application is running, but when I rebuild my model project (BM.Core), I got the following error:
, "BookManyContext", . First First Migrations (http://go.microsoft.com/fwlink/?LinkId=238269).
, , , Up Down DbMigration .
:
enable-migrations -contexttypename BookManyContext
add-migration InitialCreate3
update-database