Search code examples
c#entity-frameworkdatacontext

How do I create database using entity framework 6 datacontext?


I am trying to understand the code-first approach : http://blog.logiticks.com/an-absolute-beginner-s-tutorial-for-understanding-entity-framework-s-database-first-model-first-and-code-first-approaches/

I create the classes, then I don't know where to add the datacontext file? Note that I put my classes in models folder so should i put the context file there too? and how would the project understand where the context file is and create the database from there? I am new to entity framework, any help is appreciated


Solution

  • In EF database is created automatically, at least using Code First approach. When your application hits the context, EF will check and ensure that DB exists and is compatible with your model(OK, I have simplified this, but overall it is true).

    As someone in comments suggested, this tutorial doesn't seem like a viable source of knowledge. I strongly encourage you to read e.g. this article.